Number toPrecision
Description
toPrecision() returns either the fixed or the exponential representation of a number, depending on which makes the most sense.
This method takes one argument, which is the total number of digits to use to represent the number not including exponents.
Example
var num = 99;
console.log(num.toPrecision(1)); //"1e+2"
console.log(num.toPrecision(2)); //"99"
console.log(num.toPrecision(3)); //"99.0"
//from ww w. ja va 2s .c om
The toPrecision() method can represent numbers with 1 through 21 decimal places.
The code above generates the following result.