How do I format number with a specified number of decimals in javascript?
Viewed 19 times.
-
Example
Copy code to clipboardconst a = 10; console.log(a); console.log(a.toFixed(2));
Output
10 10.00
Additional information
The toFixed() method converts a number into a string, formatting it with a specified number of decimals.
25 Nov 2019
Author: Max Zorin
Would you recommend this example to your colleagues?