JS Built-ins
NumbertoFixedbeginner

toFixed() β€” return type is string

πŸ“– 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() Returns a String

The result is always a string, even when the number looks like an integer.

πŸ’‘ Hints (1)
  • β€’ `toFixed` returns a string; use `parseFloat` if you need the numeric value back.