PackageTop Level
Classpublic class Number
InheritanceNumber Inheritance 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;



Public Properties
 Property
  MAX_VALUE : Number
[static]The largest representable number (double-precision IEEE-754).
  MIN_VALUE : Number
[static]The smallest representable non-negative number (double-precision IEEE-754).
  NaN : Number
[static]The IEEE-754 value representing Not A Number (NaN).
  NEGATIVE_INFINITY : Number
[static]Specifies the IEEE-754 value representing negative infinity.
  POSITIVE_INFINITY : Number
[static]Specifies the IEEE-754 value representing positive infinity.
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
Creates a new Number object.
  
Returns the string representation of the specified Number object (myNumber).
  
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_VALUEproperty
public static var 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_VALUEproperty 
public static var MIN_VALUE:Number

Player version: Flash Player 5

The smallest representable non-negative 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

NaNproperty 
public static var NaN:Number

Player version: Flash Player 5

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

See also

NEGATIVE_INFINITYproperty 
public static var 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_INFINITYproperty 
public static var 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 function 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.

See also


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

Method detail
toString()method
public function toString(radix:Number):String

Player version: Flash Player 5

Returns the string representation of the specified Number object (myNumber). If the value of the Number object is a decimal number without a leading zero (such as .4), Number.toString() adds a leading zero (0.4).

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 function valueOf():Number

Player version: Flash Player 5

Returns the primitive value type of the specified Number object.

Returns
Number — A number value corresponding to the specified Number object.

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