toPrecisionintermediate// 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.
For large numbers with fewer significant digits than the number requires, exponential notation is used.
(123456789).toPrecision(4) // β '1.235e+8'