Angular 5 percent pipe digitInfo not working as expected

Wagner Danda da Silva Filho picture Wagner Danda da Silva Filho · Dec 6, 2017 · Viewed 7.3k times · Source

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?

Answer

Stefan Svrkota picture Stefan Svrkota · Dec 6, 2017

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%