JavaScript Number.prototype.toPrecision() Method
The toPrecision() method formats a number to a given number of significant digits and returns it as a string.
Description
The toPrecision() method returns a string representing the number rounded to the given number of significant digits. Depending on the size of the number, it may use exponential notation, such as "1.2e+5".
Without an argument, it behaves like toString(). Rounding follows the same floating point caveats as toFixed(), so values that can't be stored exactly may round in unexpected directions.
It's useful in scientific and measurement displays, where the number of significant figures matters more than decimal places. For user-facing numbers, Intl.NumberFormat with maximumSignificantDigits gives the same rounding plus locale-aware separators.
Syntax
number.toPrecision()
number.toPrecision(precision)Parameters
- precisionOptional. The number of significant digits, from 1 to 100.
Return Value
A string of the number rounded to that many significant digits.
Exceptions
- RangeErrorThrown if
precisionis outside 1 to 100.
Example
Browser Support
The following information will show you the current browser support for the Number.prototype.toPrecision() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





