Object | +-Number public class Number extends Object 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; Availability: ActionScript 1.0; Flash Player 5 - (became a native object in Flash Player 6, which improved performance significantly). Property summary
Properties inherited from class Object
Constructor summary
Method summary
Methods inherited from class Object
MAX_VALUE (Number.MAX_VALUE property)public static MAX_VALUE : Number The largest representable number (double-precision IEEE-754). This number is approximately 1.79e+308. Availability: ActionScript 1.0; Flash Player 5 Example The following ActionScript displays the largest and smallest representable numbers to the Output panel. trace("Number.MIN_VALUE = "+Number.MIN_VALUE); trace("Number.MAX_VALUE = "+Number.MAX_VALUE); This code displays the following values: Number.MIN_VALUE = 4.94065645841247e-324 Number.MAX_VALUE = 1.79769313486232e+308 MIN_VALUE (Number.MIN_VALUE property)public static MIN_VALUE : Number The smallest representable number (double-precision IEEE-754). This number is approximately 5e-324. Availability: ActionScript 1.0; Flash Player 5 Example The following ActionScript displays the largest and smallest representable numbers to the Output panel. trace("Number.MIN_VALUE = "+Number.MIN_VALUE); trace("Number.MAX_VALUE = "+Number.MAX_VALUE); This code displays the following values: Number.MIN_VALUE = 4.94065645841247e-324 Number.MAX_VALUE = 1.79769313486232e+308 NaN (Number.NaN property)public static NaN : Number The IEEE-754 value representing Not A Number (NaN). Availability: ActionScript 1.0; Flash Player 5 See also isNaN function NEGATIVE_INFINITY (Number.NEGATIVE_INFINITY property)public static NEGATIVE_INFINITY : Number 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. Availability: ActionScript 1.0; Flash Player 5 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 Number constructorpublic Number(num:Object) 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. Availability: ActionScript 1.0; Flash Player 5 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 toString (Number.toString method), valueOf (Number.valueOf method) POSITIVE_INFINITY (Number.POSITIVE_INFINITY property)public static POSITIVE_INFINITY : Number 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. Availability: ActionScript 1.0; Flash Player 5 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 toString (Number.toString method)public toString(radix:Number) : String Returns the string representation of the specified Number object (myNumber). Availability: ActionScript 1.0; Flash Player 5 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 (Number.valueOf method)public valueOf() : Number Returns the primitive value type of the specified Number object. Availability: ActionScript 1.0; Flash Player 5 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 |