The Number type is the reference type that corresponds to the numeric values. To create an object, a Number constructor is used with a number value passed in.

var numberObject = new Number(number);

The Number type, same as Boolean, besides traditional methods valueOf(), toLocaleString() and toString(), contains also a few additional methods. These are:

  • toFixed(); Returns a string represented as a number with a decimal point specified within apprentices;
  • toExponential(); Returns a string represented as a number formatted in exponential notation; Decimal point is also specified within apprentices;
  • toPrecision(); Returns either the fixed or exponential representation of the number depending on which makes more sense; The argument passed represents the number of digits to be used.

The toFixed() method can represent numbers with 0 through 20 decimal places, although some browsers may support more. All three methods tend to random numbers in the best possible manner.


The JavaScript Number type conversions example:


›› go to examples ››