Top Level

Class Number

Object


public class Number
extends Object

Player version: Flash Player 5 — (became a native object in Flash Player 6, which improved performance significantly).

The Number class is a simple wrapper object for the Number data type. You can manipulate primitive numeric values by using the methods and properties associated with the Number class. This class is identical to the JavaScript Number class.

The properties of the Number class are static, which means you do not need an object to use them, so you do not need to use the constructor.

The following example calls the toString() method of the Number class, which returns the string 1234:

var myNumber:Number = new Number(1234);
myNumber.toString();

The following example assigns the value of the MIN_VALUE property to a variable declared without the use of the constructor:

var smallest:Number = Number.MIN_VALUE;




Property Summary
static MAX_VALUE : Number
The largest representable number (double-precision IEEE-754).
static MIN_VALUE : Number
The smallest representable number (double-precision IEEE-754).
static NaN : Number
The IEEE-754 value representing Not A Number (NaN).
static NEGATIVE_INFINITY : Number
Specifies the IEEE-754 value representing negative infinity.
static POSITIVE_INFINITY : Number
Specifies the IEEE-754 value representing positive infinity.

Properties inherited from class Object
__proto__, __resolve, constructor, prototype


Constructor Summary
Number(num:Object)
Creates a new Number object.


Method Summary
toString(radix:Number) : String
Returns the string representation of the specified Number object (myNumber).
valueOf() : Number
Returns the primitive value type of the specified Number object.

Methods inherited from class Object
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch


Property Detail

MAX_VALUE Property

public static MAX_VALUE : Number

Player version: Flash Player 5

The largest representable number (double-precision IEEE-754). This number is approximately 1.79e+308.

Example
The following ActionScript displayswrites the largest and smallest representable numbers to the Output panelto the log file.
trace("Number.MIN_VALUE = "+Number.MIN_VALUE);
trace("Number.MAX_VALUE = "+Number.MAX_VALUE);

This code logsdisplays the following values:

Number.MIN_VALUE = 4.94065645841247e-324
Number.MAX_VALUE = 1.79769313486232e+308


MIN_VALUE Property

public static MIN_VALUE : Number

Player version: Flash Player 5

The smallest representable number (double-precision IEEE-754). This number is approximately 5e-324.

Example
The following ActionScript displayswrites the largest and smallest representable numbers to the Output panelto the log file.
trace("Number.MIN_VALUE = "+Number.MIN_VALUE);
trace("Number.MAX_VALUE = "+Number.MAX_VALUE);

This code logsdisplays the following values:

Number.MIN_VALUE = 4.94065645841247e-324
Number.MAX_VALUE = 1.79769313486232e+308


NaN Property

public static NaN : Number

Player version: Flash Player 5

The IEEE-754 value representing Not A Number (NaN).

See also
isNaN() global function

NEGATIVE_INFINITY Property

public static NEGATIVE_INFINITY : Number

Player version: Flash Player 5

Specifies the IEEE-754 value representing negative infinity. The value of this property is the same as that of the constant -Infinity.

Negative infinity is a special numeric value that is returned when a mathematical operation or function returns a negative value larger than can be represented.

Example
This example compares the result of dividing the following values.
var posResult:Number = 1/0;
if (posResult == Number.POSITIVE_INFINITY) {
    trace("posResult = "+posResult); // output: posResult = Infinity
}
var negResult:Number = -1/0;
if (negResult == Number.NEGATIVE_INFINITY) {
    trace("negResult = "+negResult); // output: negResult = -Infinity


POSITIVE_INFINITY Property

public static POSITIVE_INFINITY : Number

Player version: Flash Player 5

Specifies the IEEE-754 value representing positive infinity. The value of this property is the same as that of the constant Infinity.

Positive infinity is a special numeric value that is returned when a mathematical operation or function returns a value larger than can be represented.

Example
This example compares the result of dividing the following values.
var posResult:Number = 1/0;
if (posResult == Number.POSITIVE_INFINITY) {
    trace("posResult = "+posResult); // output: posResult = Infinity
}
var negResult:Number = -1/0;
if (negResult == Number.NEGATIVE_INFINITY) {
    trace("negResult = "+negResult); // output: negResult = -Infinity



Constructor Detail

Number Constructor

public Number(num:Object)

Player version: Flash Player 5

Creates a new Number object. The new Number constructor is primarily used as a placeholder. A Number object is not the same as the Number() function that converts a parameter to a primitive value.

Parameters
num:Object — The numeric value of the Number object being created or a value to be converted to a number. The default value is 0 if value is not provided.

Example
The following code constructs new Number objects:
var n1:Number = new Number(3.4);
var n2:Number = new Number(-10);

See also
Number.toString(), Number.valueOf()


Method Detail

toString Method

public toString(radix:Number) : String

Player version: Flash Player 5

Returns the string representation of the specified Number object (myNumber).

Parameters
radix:Number — Specifies the numeric base (from 2 to 36) to use for the number-to-string conversion. If you do not specify the radix parameter, the default value is 10.

Returns
String — A string.

Example
The following example uses 2 and 8 for the radix parameter and returns a string that contains the corresponding representation of the number 9:
var myNumber:Number = new Number(9);
trace(myNumber.toString(2)); // output: 1001
trace(myNumber.toString(8)); // output: 11
The following example results in a hexadecimal value.
var r:Number = new Number(250);
var g:Number = new Number(128);
var b:Number = new Number(114);
var rgb:String = "0x"+ r.toString(16)+g.toString(16)+b.toString(16);
trace(rgb); 
// output: rgb:0xFA8072 (Hexadecimal equivalent of the color 'salmon')


valueOf Method

public valueOf() : Number

Player version: Flash Player 5

Returns the primitive value type of the specified Number object.

Returns
Number — A string.

Example
The following example results in the primative value of the numSocks object.
var numSocks = new Number(2);
trace(numSocks.valueOf()); // output: 2