Using the below code in Angular to cast the number to 2 decimal places using DecimalPipe
.
constructor(private decimalPipe: DecimalPipe) {}
this.decimalPipe.transform('0','.2-2') //output 0.00
Any ideas of theTypeScript
equivalent?
toPrecision(2)
doesn't works the same
e.g.
var num = 2;
2.toPrecision(2)
Expected: 2.00
Actual: 2.0