Number.toFixed() Format with fixed decimals
Last updated: 2026-09-09
Number.toFixed() Format with fixed decimals
toFixed formats a number with fixed decimal places, returning a string.
| Category | Numbers |
|---|---|
| ES version | ES3 |
📝 Syntax
const str = number.toFixed(digits);
⚙️ Parameters
| digits | Optional. Decimal places, default 0; range 0~100. |
|---|
Returns:A formatted string (not a number).
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
19.99
20
0.3333
0.30
💡 Tip toFixed returns a string — use Number() to convert back for math.
⚠️ Warning 0.1 + 0.2 = 0.30000000000000004 — use toFixed(2) for display.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| Number.toFixed() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
QDoes toFixed return a number or string?
AA string — use Number(num.toFixed(2)) for math.
QRound or truncate?
ARounds (with banker's rounding edge cases).
QHow to fix floating-point precision?
AtoFixed(2) for display; integer math or Decimal lib for precision.