Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 469
Wagner Danda da Silva Filho Avatar asked Dec 06 '17 14:12

Wagner Danda da Silva Filho


People also ask

What is the default value of minIntegerDigits while using the DecimalPipe?

minIntegerDigits : The minimum number of integer digits before the decimal point. Default is 1.

What is decimal pipe in angular?

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.


1 Answers

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%
like image 96
Stefan Svrkota Avatar answered Sep 17 '22 21:09

Stefan Svrkota