Here is a code snippet in Angular that demonstrates how to format a number to two decimal places using the DecimalPipe
.
constructor(private decimalPipe: DecimalPipe) {}
this.decimalPipe.transform('0','.2-2') //output 0.00
Are there any suggestions on achieving something similar in TypeScript
?
Using toPrecision(2)
does not produce the same result.
For example:
var num = 2;
2.toPrecision(2)
Expected output: 2.00
Actual output: 2.0