How to format numbers to two decimal places
- Previous Page Redirect Web Page
- Next Page Hover Zoom
Learn how to format numbers to two decimal places in JavaScript.
to format the number to two decimal places
You can use toFixed()
The method formats the number to display only two decimal places. Note that the result is rounded (displaying 5.57 instead of 5.56):
Example
let num = 5.56789; let n = num.toFixed(2); // 5.57
If you want to display three decimal places, just change the number to 3:
Example
let num = 5.56789; let n = num.toFixed(3); // 5.568
Related Pages
Reference Manual:JavaScript Number toFixed() Method
- Previous Page Redirect Web Page
- Next Page Hover Zoom