If I do this in an Angular 5 template:
{{0.7 | percent:'1.2-5'}}
I get this as expected: 70.00%
However, when I do this:
{{0.07 | percent:'1.2-5'}}
I get 7.00000%
instead of what the expected 7.00%
Am I just doing something wrong or is this a bug in Angular?
minIntegerDigits : The minimum number of integer digits before the decimal point. Default is 1.
Pipes in Angular are used for transforming or formatting data in the template without writing boilerplate code logic in the component. The decimal pipe is a built-in Angular pipe. In brief, the decimal pipe transforms a value of type number into a string based on the formatting rules that you specify.
Seems like a bug with DecimalPipe because PercentPipe uses it for formatting. Simple removal of maxFractionDigits
which is the maximum number of digits after fraction (default is 3
) will get you the desired result:
{{0.7 | percent:'1.2'}} --> 70.00%
{{0.07 | percent:'1.2'}} --> 7.00%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With