Search code examples
angularangular-pipe

Angular 5 percent pipe digitInfo not working as expected


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?


Solution

  • 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%