Table of Contents

Number Class Flash 5

wrapper class for primitive numeric data

Constructor

new Number(value)

Arguments

value

An expression to be resolved and, if necessary, converted to a numeric value, then wrapped in a Number object.

Class Properties

The following properties are accessed directly as properties of the Number class, using Number.propertyName. To access them you do not need to instantiate a new Number object (i.e., there is no need for the constructor function). Some of these properties, such as NaN, don't even require the Number.propertyName notation. You can simply use NaN as shorthand for Number.NaN (details follow in entries for each property).

MAX_VALUE

The largest representable positive number in ActionScript.

MIN_VALUE

The smallest representable positive number in ActionScript.

NaN

Special Not-a-Number value indicating invalid numeric data.

NEGATIVE_INFINITY

Any number more negative than -MAX_VALUE.

POSITIVE_INFINITY

Any number larger than MAX_VALUE.

Methods

toString( )

Convert a number to a string.

Description

The Number class has two purposes:

Usage

There is no need to create a Number object if you simply want to access the numeric properties it defines. In fact, where applicable, it is easier to use global property equivalents (NaN, Infinity, and -Infinity). Frankly, it is rare that you'll need the Number class properties at all.

On the other hand, the Number class's toString( ) method is used with a Number object. However, the interpreter takes care of creating a Number instance for us whenever we invoke a method on a primitive numeric value. For example, here we use toString( ) to convert a decimal number to its hexadecimal equivalent:

x = 102;
hex = x.toString(16);  // A Number instance is automatically and (temporarily)
                       // created to "wrap" x for the sake of this operation.

As this is a fairly rare task, you probably won't be using instances of the Number class much.

See Also

The Math object; "Section 4.1


Table of Contents