JavaScript Number.prototype.toFixed() Method
The toFixed() method formats a number with a fixed number of decimal places and returns it as a string.
Description
The toFixed() method formats a number using fixed-point notation, with exactly the given number of digits after the decimal point, padding with zeros or rounding as needed. It returns a string, so convert back with Number() if you need to do more maths.
Rounding can look wrong for values that aren't stored exactly: (1.005).toFixed(2) gives "1.00" because 1.005 is really 1.00499999... For displaying prices to users, Intl.NumberFormat or toLocaleString() also adds the right separators and symbols.
Numbers with an absolute value of 1021 or more are returned in exponential notation instead. Negative numbers keep their sign, and the result never includes a thousands separator.
Syntax
number.toFixed()
number.toFixed(digits)Parameters
- digitsOptional. The number of digits after the decimal point, from 0 to 100. Defaults to 0.
Return Value
A string with the number rounded to that many decimal places.
Exceptions
- RangeErrorThrown if
digitsis outside 0 to 100.
Example
Browser Support
The following information will show you the current browser support for the Number.prototype.toFixed() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





