Reputation: 1
I want to convert number to percentage format like 25 to 25.00% with angular percentage pipe.I have used this one.
{{ number | percent : '0.2-2'}}
I am getting like this 2,500.00%.any one can help me with this?
Upvotes: 0
Views: 987
Reputation: 11
You need to divide the number by 100 to get the desired output.
Input:
const number = 25;
{{ number/100 | percent : '0.2'}}
Output:
25.00%
Upvotes: 1
Reputation: 1073
Probably you're using it with a big number, check this example on stackblitz. Remember that 1
equals 100%
, so to show 25%
, you need to put 0.25
Also, check the docs and their examples, should be doubtless
https://stackblitz.com/edit/angular-ivy-iszurj?file=src%2Fapp%2Fapp.component.html
https://angular.io/api/common/PercentPipe
Upvotes: 2