HTML and CSS Reference
In-Depth Information
or an object number type and JavaScript manages the conversion back and forth as neces-
sary. The Number object was introduced in JavaScript 1.1.
The Number() constructor takes a numeric value as its argument. If used as a func-
tion, without the new operator, the argument is converted to a primitive numeric value,
and that number is returned; if it fails, NaN is returned. The Number object has a number
of properties and methods, as listed in Tables 9.11 and 9.12.
FORMAT
var number = new Number(numeric value); //Object
var number = numeric value; // Primitive data type
EXAMPLE
var n = new Number(65.7);
var n = 65.7;
Table 9.11 The Number Object's Properties
Property
What It Describes
MAX_VALUE
The largest representable number, 1.7976931348623157e+308
MIN_VALUE
The smallest representable number, 5e-324
NaN
Not-a-number value
NEGATIVE_INFINITY
Negative infinite value; returned on overflow
POSITIVE_INFINITY
Infinite value; returned on overflow
prototype
Used to customize the Number object by adding new properties
and methods
Table 9.12 The Number Object's Methods
Method
What It Does
toString()
Converts a number to a string using a specified base (radix)
toLocaleString()
Converts a number to a string using local number conventions
toFixed()
Converts a number to a string with a specified number of places after the
decimal point
toExponential()
Converts a number to a string using exponential notation and a specified
number of places after the decimal point
toPrecision()
Converts a number to a string in either exponential or fixed notation
containing the specified number of places after the decimal point
 
Search WWH ::




Custom Search