MENU
Number Prototype Methods
Number.prototype.valueOf()
Returns the primitive value of the specified object. Called automatically when the object is treated as a primitive other than a string, it overrides the Object.prototype.valueOf()method.
Number.prototype.toExponential()
Returns a string representing the number in exponential notation.
Number.prototype.toFixed()
Returns a string representing the number in fixed-point notation.
Number.prototype.toPrecision()
Returns a string representing the number to a specified precision in fixed-point or exponential notation.
Number.prototype.toString()
Returns a string representing the specified object in the specified radix (base). The inverse function is parseInt(s,r). This function is also called automatically when the object is treated as a string.
Number.prototype.toLocaleString()
Returns a string with a language sensitive representation of this number. Overrides the Object.prototype.toLocaleString() method.(Refer to 6.20 for related information on Intl.)
var n = 123.456;
console.log(n.valueOf());
console.log(n.toExponential());
console.log(n.toExponential(4));
console.log(n.toFixed());
console.log(n.toFixed(4));
console.log(n.toPrecision());
console.log(n.toPrecision(4));
console.log(n.toString() + 999);
console.log(n.toString(16));
console.log((1234567).toLocaleString());
console.log((123.4).toLocaleString("zh-Hans-CN-u-nu-hanidec"));
console.log((2500).toLocaleString("en-GB", { style: "currency", currency: "GBP", minimumFractionDigits: 2 }));