Favorites

JavaScript Number.prototype.toPrecision() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Number.prototype.toPrecision()
JavaScript Number Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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 precision is outside 1 to 100.

Example

const n = 123.456;
console.log(n.toPrecision(4));
console.log(n.toPrecision(2));
console.log((0.000123).toPrecision(2));
console.log((123456).toPrecision(2));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee