JS Built-ins
NumbertoPrecisionintermediate

toPrecision() β€” 5 significant digits

πŸ“– Usage Example
// Format number to a specified precision
(123.456).toPrecision(5)    // β†’ '123.46'
(0.000123).toPrecision(2)   // β†’ '0.00012'

Use toPrecision() to format a number to a total number of significant digits, which is useful in scientific or measurement contexts.

Number.prototype.toPrecision()

num.toPrecision(precision?) returns a string with the specified number of significant digits.

(123.456).toPrecision(5)  // β†’ '123.46'
πŸ’‘ Hints (1)
  • β€’ `toPrecision` counts significant digits, not just decimal places.