Team LiB   Previous Section   Next Section
Number Core JavaScript 1.1; JScript 2.0; ECMA v1

support for numbers

Constructor

new Number(value)
Number(value)

With the new operator, the Number( ) constructor converts its argument to a numeric value and returns a new Number object wrapped around that value. Without new, Number( ) is a conversion function that converts its argument to a number and returns that value.

Constants

These constants are properties of Number itself, not of individual Number objects.

Number.MAX_VALUE

The largest representable number. Approximately 1.79E+308.

Number.MIN_VALUE

The smallest representable number. Approximately 5E-324.

Number.NaN

Not-a-number value. Same as the global NaN.

Number.NEGATIVE_INFINITY

Negative infinite value.

Number.POSITIVE_INFINITY

Infinite value. Same as global Infinity.

Methods

toExponential( digits)

Returns a string representation of the number, in exponential notation, with one digit before the decimal place and digits digits after the decimal place. The fractional part of the number is rounded, or padded with zeros so that it has the specified length. digits must be between 0 and 20, and if omitted, as many digits as necessary are used. JS 1.5; JScript 5.5; ECMA v3.

toFixed( digits)

Returns a string representation of the number that does not use exponential notation, and has exactly digits digits after the decimal place. digits must be between 0 and 20. The number is rounded or padded with zeros if necessary. JS 1.5; JScript 5.5; ECMA v3.

toLocaleString( )

Returns an implementation-dependent string representation of the number, formatted according to local conventions. This may affect things such as the punctuation characters used for the decimal point and the thousands separator. JS 1.5; JScript 5.5; ECMA v3.

toPrecision( precision)

Returns a string representation of number that contains precision significant digits. precision must be between 1 and 21. The returned string uses fixed-point notation where possible, or exponential notation otherwise. The number is rounded or padded with zeros if necessary. JS 1.5; JScript 5.5; ECMA v3.

toString( radix)

Converts a number to a string, using a specified radix (base), and returns the string. radix must be between 2 and 36. If omitted, base 10 is used.

See Also

Math

    Team LiB   Previous Section   Next Section