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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

number.toPrecision(precision)

Parameters

ParameterDescription
precision optional Significant digits, 1 to 100.

Return value

A string.

Examples

Significant digitsTry it yourself
const n = 123.456;
console.log(n.toPrecision(4), n.toPrecision(2), (0.000123).toPrecision(2));

Output

123.5 1.2e+2 0.00012
Large numbers switch to exponential notationTry it yourself
console.log((1234567).toPrecision(3));

Output

1.23e+6

Version history

VersionChange
JavaScript ES3Added

Was this page helpful?