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>
  
Click to view the demo

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
Home 
  JavaScript Book 
    Essential Types  

Number:
  1. The Number Type
  2. Number toExponential()
  3. Number toFixed()
  4. Number toPrecision()
  5. Number toString()
  6. Number valueOf()
  7. Converting Strings to Numbers
  8. typeof and instanceof for Number objects and primitive values