Represents a number either in exponential or fixed-point notation with a specified number of digits.
SyntaxtoPrecision([ precision ])
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
, toString()
is called instead.
Using toPrecision
to format the decimal presentation of a number.
var pie = 3.14159;
pie.toPrecision();
pie.toPrecision(5);
pie.toPrecision(2);
pie.toPrecision(1);
(1234.5).toPrecision(2);
Remarks Throws
RangeError
when a fractionDigits outside the bounds of 1 - 21 (inclusive) was given.
15.7.4.7 Number.prototype.toPrecision(precision)
ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011
AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4