|-||myNumber = Number|
|Object properties:||constructor, prototype|
|Class constants:||MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY|
|Object methods:||toExponential(), toFixed(), toLocaleString(), toPrecision(), toSource(), toString(), valueOf()|
An instance of the class Number is created by using the new operator on the Number() constructor. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms.
All properties and methods of the prototype are available as if they were part of the instance.
A number object is a member of the type Object and is an instance of the built-in Number object.
Number objects are created by cloning the built-in Number object. This is done by calling the Number constructor with the new operator being applied to an existing Number object. Thus:
myNumber = new Number(1000);
A Number object can be coerced to a number value and can be used anywhere where a number value would be expected.
Programmers familiar with object-oriented techniques may prefer to use the Number object while procedural language programmers may implement the same functionality with a number value instead.
The prototype for the Number prototype object is the Object prototype object.
You might want to add useful methods to the Number.prototype to output numbers in unusual formats. For example you could implement a roman numeral conversion method. Adding that to the prototype would let you output year numbers in classical formats.
The Number object provides a collection of static constant values by way of properties belonging to the integral Number object. Because the mathematical mechanisms of any application tend to be provided by the operating system, you should find that between different browsers on any particular platform, the values that these constants yield will be very consistent.
The ECMA standard lays down strict values for these properties and in general the browser manufacturers try to comply, but there is always the possibility that an implementation may use a non-compliant calculation.
However, it may not be quite so reliable across platforms. You might enumerate one of these constants as you are authoring and then hard code that value into your script. When that script is executed on another platform, even in the same browser, the internal numeric support may yield a different value.
You should always refer to the static constants using their symbolic names and not define them yourself, unless you are certain that the script is running on a platform that does not already define the constant value.
ECMA 262 edition 2 - section - 4.3.20
ECMA 262 edition 2 - section - 10.1.5
ECMA 262 edition 2 - section - 15.7
ECMA 262 edition 3 - section - 4.3.21
ECMA 262 edition 3 - section - 10.1.5
ECMA 262 edition 3 - section - 15.7