I am looking for a pipe that transforms like below, just wanted to round 2 decimal points.
I tried [ngModel]="item.value | number number:'1.0-X'"
, but it's not working in all cases
239.779 > 239.78
0.674 > 0.67
35355.453 > 35355.45
I am looking for a pipe that transforms like below, just wanted to round 2 decimal points.
I tried [ngModel]="item.value | number number:'1.0-X'"
, but it's not working in all cases
239.779 > 239.78
0.674 > 0.67
35355.453 > 35355.45
You can use DecimalPipe.
x.x-x minIntegerDigits: The minimum number of integer digits before the decimal point. Default is 1.
x.x-x minFractionDigits: The minimum number of digits after the decimal point. Default is 0.
x.x-x maxFractionDigits: The maximum number of digits after the decimal point. Default is 3.
For exactly two decimals and at least one number before decimal you can write like this:
[ngModel]="item.value | number:'1.2-2'"
or since minIntegerDigits default is 1: [ngModel]="item.value | number:'.2-2'"
If you are interested in locale-specific configurations you can read this article:
Seperate the banana binding to: event (ngModelChange) and property [ngModel] parts (ngModelChange)="Rate1=$event" [ngModel]="Rate1 | number:'1.2-2' ".
where 1.2-2 is as follows:
Decimal representation options, specified by a string in the following format:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.
You may use it according to your requirements.
Also refer to- https://stackblitz.com/edit/decimal-pipe-example?file=app%2Fapp.component.html