JS Built-ins
NumbertoFixedintermediate

toFixed() β€” safe rounding example

πŸ“– Usage Example
// Format number with fixed decimal places
(3.14159).toFixed(2)   // β†’ '3.14'
(1.5).toFixed(0)       // β†’ '2'
(100).toFixed(2)       // β†’ '100.00'

Use toFixed() to format a number as a string with a specific number of decimal places, commonly used for monetary values.

toFixed() β€” Reliable Rounding

(1.25).toFixed(1) reliably returns '1.3'.

πŸ’‘ Hints (1)
  • β€’ Some values (like `1.005`) are tricky due to floating-point representation; prefer values like `1.25`.