JS Built-ins
NumbertoPrecisionbeginner

toPrecision() β€” no argument returns same as toString

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

toPrecision() β€” No Argument

Calling toPrecision() with no argument returns the same as .toString().

πŸ’‘ Hints (1)
  • β€’ Without an argument, `toPrecision()` uses the full precision of the number.