Favorites

JavaScript Number.prototype.toFixed() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Number.prototype.toFixed()
JavaScript Number Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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 digits is outside 0 to 100.

Example

console.log((3.14159).toFixed(2));
console.log((5).toFixed(2));
console.log((1.005).toFixed(2));
console.log(typeof (2.5).toFixed(1));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee