24.137. Number.toPrecision( ): format the significant digits of a numberECMAScript v324.137.1. Synopsisnumber.toPrecision(precision) 24.137.1.1. Arguments
24.137.1.2. ReturnsA string representation of number that contains precision significant digits. If precision is large enough to include all the digits of the integer part of number, the returned string uses fixed-point notation. Otherwise, exponential notation is used with one digit before the decimal place and precision-1 digits after the decimal place. The number is rounded or padded with zeros as necessary. 24.137.1.3. Throws
24.137.2. Examplevar n = 12345.6789; n.toPrecision(1); // Returns 1e+4 n.toPrecision(3); // Returns 1.23e+4 n.toPrecision(5); // Returns 12346: note rounding n.toPrecision(10); // Returns 12345.67890: note added zero 24.137.3. See AlsoNumber.toExponential( ), Number.toFixed( ), Number.toLocaleString( ), Number.toString( ) |