JS Built-ins
NumbertoFixedbeginner

toFixed() β€” basic usage

πŸ“– 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.

Number.prototype.toFixed()

num.toFixed(digits?) returns a string with a fixed number of decimal places.

(3.14159).toFixed(2)  // β†’ '3.14'
πŸ’‘ Hints (1)
  • β€’ `toFixed` rounds and pads the decimal portion to the specified number of digits.