0

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?

2 Answers 2

2

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

1

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%

Not the answer you're looking for? Browse other questions tagged or ask your own question.