AD · 728×90
Google AdSense / Яндекс.Директ
Google AdSense / Яндекс.Директ
Number
Number.toFixed()
Formats a number to a fixed number of decimal places, returns a string
Number to format
Number of decimal places
(number).toFixed(digits)
RESULT
— click Run or press Ctrl+Enter —
Parameter Reference
| Parameter | Type | Status | Description |
|---|---|---|---|
| number | number | required | Number to format |
| digits | number | optional | Number of decimal places |
About
toFixed() formats a number to a specified number of digits after the decimal point and returns a string. Used for prices, financial data, measurement display. Due to IEEE 754 float representation, (1.005).toFixed(2) may return "1.00" instead of "1.01" — this is a float limitation, not a function bug.
Browser Support
Available since ES3 (1999). Part of Number.prototype. Similar: toPrecision() for total significant digits, toExponential() for scientific notation.
Tips & Gotchas
- (1.005).toFixed(2) may give "1.00" — use Math.round(num * 100) / 100 for accuracy
- toFixed() returns a string — for arithmetic: +((1.23).toFixed(1))
- for finance consider decimal.js.