The Number Type
The Number type is the reference type for numeric values. To create a Number object, use the Number constructor and pass in any number.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var numberObject = new Number(10);
document.writeln(numberObject);
</script>
</head>
<body>
</body>
</html>
Useful Number-to-String Methods
string toString()
- Represents a number in base 10
string toString(2)
- Represents a number in base 2(binary)
string toString(8)
- Represents a number in base 8(octal)
string toString(16)
- Represents a number in base 16(hexadecimal)
string toFixed(n)
- Represents a real number with n digits after the decimal point
string toExponential(n)
- Represents a number using exponential notation with one digit before the decimal point and n digits after
string toPrecision(n)
- Represents a number with n significant digits, using exponential notation if required
valueOf
- returns the primitive numeric value represented by the object