JavaScript (ES2026) reference · Number Methods and Properties
JavaScript number.toPrecision() Method
Format a number to a given number of significant digits, using exponential notation when needed.
JavaScript (ES2026) Since ES3
Syntax
number.toPrecision(precision)
Parameters
| Parameter | Description |
|---|---|
precision optional |
Significant digits, 1 to 100. |
Return value
A string.
Examples
const n = 123.456;
console.log(n.toPrecision(4), n.toPrecision(2), (0.000123).toPrecision(2));
Output
123.5 1.2e+2 0.00012
console.log((1234567).toPrecision(3));
Output
1.23e+6
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
Related
number.toFixed()· Format a number with a fixed number of decimal places, returned as a string. Rounds, but floating-point quirks apply.- JavaScript Numbers · tutorial
- JavaScript Type Conversion · tutorial