★ wanayoo — archive 1999 http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/NumberNouvelle recherche | Portail wanayoo

Mozilla.com

Number

Summary

Creates a wrapper object to allow you to work with numerical values.

Syntax

new Number(value)

Parameters

value
The numeric value of the object being created.

Description

The primary uses for the Number object are:

If the argument cannot be converted into a number, it returns Nan.

In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.

Properties

For properties inherited by Number instances, see Properties of Number instances.

MAX_VALUE
The largest representable number.
MIN_VALUE
The smallest representable number.
NaN
Special "not a number" value.
NEGATIVE_INFINITY
Special value representing negative infinity; returned on overflow.
POSITIVE_INFINITY
Special value representing infinity; returned on overflow.
prototype
Allows the addition of properties to a Number object.

Properties inherited from Function.prototype
caller, constructor, length, name

Methods

For methods inherited by Number instances, see Methods of Number instances.

Although the Number object contains no methods of its own, it does inherit some methods through the prototype chain.

Methods inherited from Function.prototype
apply, call, toSource, toString, valueOf

Number instances

All Number instances inherit from Core_JavaScript_1.5_Reference:Global_Objects:Number:prototype

Examples

Example: Using the Number object to assign values to numeric variables

The following example uses the Number object's properties to assign values to several numeric variables:

biggestNum = Number.MAX_VALUE;
smallestNum = Number.MIN_VALUE;
infiniteNum = Number.POSITIVE_INFINITY;
negInfiniteNum = Number.NEGATIVE_INFINITY;
notANum = Number.NaN;

Example: Using Number to convert a Date object

The following example converts the Date object to a numerical value using Number as a function:

var d = new Date("December 17, 1995 03:24:00");
print(Number(d));

This displays "819199440000".

See also

Page last modified 13:03, 6 Apr 2008 by Potappo

Tags:

Files (0)