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.)
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var n = 123.456;
console.log(n.valueOf()); // 123.456
console.log(n.toExponential()); // 1.23456e+2
console.log(n.toExponential(4)); // 1.2346e+2
console.log(n.toFixed()); // 123
console.log(n.toFixed(4)); // 123.4560
console.log(n.toPrecision()); // 123.456
console.log(n.toPrecision(4)); // 123.5
console.log(n.toString()+999); // 123.456999
console.log(n.toString(16)); // 7b.74bc6a7ef9dc
console.log((1234567).toLocaleString()); // 1,234,567
console.log((123.4).toLocaleString(
"zh-Hans-CN-u-nu-hanidec")); // 一二三.四
console.log((2500).toLocaleString("en-GB", {style:
"currency", currency: "GBP", minimumFractionDigits: 2})); //£2,500.00
</script></body><html>