JavaScript (ES2026) reference · Number Methods and Properties

JavaScript number.toFixed() Method

Format a number with a fixed number of decimal places, returned as a string. Rounds, but floating-point quirks apply.

JavaScript (ES2026) Since ES3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

number.toFixed(digits)

Parameters

ParameterDescription
digits optional Decimal places, 0 to 100. Default: 0

Return value

A string.

Examples

Two decimal placesTry it yourself
const price = 1234.5;
console.log(price.toFixed(2), (0.1 + 0.2).toFixed(2), typeof price.toFixed(2));

Output

1234.50 0.30 string
1.005 is stored as 1.00499…Try it yourself
console.log((1.005).toFixed(2), (1.0051).toFixed(2));

Output

1.00 1.01

Version history

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?