JS Built-ins
NumbertoPrecisionintermediate

toPrecision() β€” large number uses exponential notation

πŸ“– 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() β€” Exponential Notation

For large numbers with fewer significant digits than the number requires, exponential notation is used.

(123456789).toPrecision(4)  // β†’ '1.235e+8'
πŸ’‘ Hints (1)
  • β€’ When the precision is less than the number of digits, exponential notation is used.