JavaScript Number toFixed()

The syntax of the toFixed() method is:

num.toFixed(digits)

Here, num is a number.


Number toFixed() Parameters

The toFixed() method takes in:

  • digits (Optional) - Value between 0 and 20 representing the number of digits to appear after the decimal point. By default, it is 0.

Return value from Number toFixed()

  • Returns a String representing the given number using fixed-point notation.

Note: The toFixed() method throws a RangeError if digits is not in between 1 and 100.


Example: Using Number toFixed()

Output

58
57.8
57.7758300
57.78
568000000000000000000.00
0.00
-2.3

Recommended Readings: