The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

toPrecision Method (Number) (JavaScript)

Represents a number either in exponential or fixed-point notation with a specified number of digits.



Required. A Number object.


Optional. The number of significant digits. Must be in the range 1 – 21, inclusive.

For numbers in exponential notation, precision - 1 digits are returned after the decimal point. For numbers in fixed notation, precision significant digits are returned.

If precision is not supplied or is undefined, the toString method is called instead.

The following code shows how to use toPrecision.

var num = new Number(123);
var prec = num.toPrecision();

num = new Number(123.456);
prec = num.toPrecision(5);

// Output:
// 123
// 123.46

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: Number Object (JavaScript)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft