How To Format A Number With Decimals In JavaScript??

Many developers ask their seniors about formatting a number with decimal points in javascript. For this, we can use the toFixed() method in the javascript to format a number with a decimal.

Use JavaScript's toFixed() method to format a number with decimals. The toFixed() method formats a number with a specific number of digits to the right of the decimal. It returns a string representation of the number that does not use exponential notation and has the exact number of digits after the decimal place.

For example:

You can try to run the following code to format a number with two decimals. Add the parameter of the toFixed() method to 3, for getting numbers with three decimals



JavaScript toFixed() Method



num1.toFixed() is : 14.700
nu2m.toFixed() is : 1355.223