Creates a wrapper object to allow you to work with numerical values.
The primary uses for the Number object are:
If the argument cannot be converted into a number, it returns NaN.
In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.
Functions:
toExponential( fractionDigits ) : String
Returns a string representing the number in exponential notation.
var num = 77.1234;
console.log("num.toExponential() is " + num.toExponential());
console.log("num.toExponential(4) is " + num.toExponential(4));
console.log("num.toExponential(2) is " + num.toExponential(2));
console.log("77.1234.toExponential() is " + 77.1234.toExponential());
console.log("77 .toExponential() is " + 77.toExponential());
OUTPUT:
num.toExponential() is 7.71234e+1 Main.js?_dc=1397732393646:16
num.toExponential(4) is 7.7123e+1 Main.js?_dc=1397732393646:18
num.toExponential(2) is 7.71e+1 Main.js?_dc=1397732393646:20
77.1234.toExponential() is 7.71234e+1 Main.js?_dc=1397732393646:22
77 .toExponential() is 7.7e+1
toFixed( digits ) : String
Returns a string representing the number in fixed-point notation.
var num 77.1234;
console.log(num.toFixed(2));
OUTPUT:
77.12
toPrecision( precision ) : String
Returns a string representing the number to a specified precision in fixed- point or exponential notation.
console.log(num.toPrecision(3));
console.log(num.toPrecision(4));
OUTPUT:
77.1
77.12
toString( radix ) : String
Returns a string representing the specified object. Overrides the Object.prototype.toString method.
var count = 10;
console.log(count.toString());
console.log((17).toString());
OUTPUT:
10
17
valueOf( ) : Number
Returns the primitive value of the specified object. Overrides the Object.prototype.valueOf method.
var x = new Number(56.43);
console.log(x.valueOf());
OUTPUT:
56.43