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
Syntax
number.toFixed(digits)
Parameters
| Parameter | Description |
|---|---|
digits optional |
Decimal places, 0 to 100. Default: 0 |
Return value
A string.
Examples
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
console.log((1.005).toFixed(2), (1.0051).toFixed(2));
Output
1.00 1.01
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
In other languages
format()· Pythonnumber_format()· PHP
Related
number.toPrecision()· Format a number to a given number of significant digits, using exponential notation when needed.number.toLocaleString()· Format a number for display using locale rules: thousands separators, decimals, currency and percentages.Math.round()· Round a number to the nearest integer; halves round up towards +Infinity, so Math.round(-2.5) is -2.- JavaScript Numbers · tutorial
- JavaScript Type Conversion · tutorial