JS Built-ins
NumbertoFixedbeginner

toFixed() β€” rounding to 0 decimal places

πŸ“– 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(0) β€” Integer Rounding

(1234.5).toFixed(0) rounds to the nearest integer and returns a string.

πŸ’‘ Hints (1)
  • β€’ `toFixed(0)` rounds to the nearest integer but still returns a string.