| Package | Top Level |
| Class | public final class Number |
| Inheritance | Number Object |
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 Number data type adheres to the double-precision IEEE-754 standard.
The Number data type is useful when you need to use floating-point values.
Flash Player handles int and uint more efficiently than Number, but Number is
useful in situations where the range of values required exceeds the valid range
of the int and uint data types. The Number class can be used to
represent integer values well beyond the valid range of the int and uint data types.
The Number data type can use up to 53 bits to represent integer values, compared to
the 32 bits available to int and uint. The default value of a variable typed as Number is NaN (Not a Number).
| int, uint |
| Property | Defined by | ||
|---|---|---|---|
| MAX_VALUE : Number
[static]
The largest representable number (double-precision IEEE-754).
| Number | ||
| MIN_VALUE : Number
[static]
The smallest representable non-negative, non-zero, number (double-precision IEEE-754).
| Number | ||
| NaN : Number
[static]
The IEEE-754 value representing Not a Number (
NaN). | Number | ||
| NEGATIVE_INFINITY : Number
[static]
Specifies the IEEE-754 value representing negative infinity.
| Number | ||
| POSITIVE_INFINITY : Number
[static]
Specifies the IEEE-754 value representing positive infinity.
| Number | ||
| Function | Defined by | ||
|---|---|---|---|
|
Creates a
Number with the specified value. | Number | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Returns a string representation of the number in exponential notation.
| Number | ||
|
Returns a string representation of the number in fixed-point notation.
| Number | ||
|
Returns a string representation of the number either in exponential notation or in
fixed-point notation.
| Number | ||
|
Returns the string representation of the specified Number object (
myNumber). | Number | ||
|
Returns the primitive value type of the specified Number object.
| Number | ||
public static const MAX_VALUE:Number
public static const MIN_VALUE:Number
-Number.MAX_VALUE.
public static const NEGATIVE_INFINITY:Number
-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.
public static const POSITIVE_INFINITY:Number
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.
public function Number(num:Object)
Number with the specified value. This constructor has the same effect
as the Number() public native function that converts an object of a different type
to a primitive numeric value.
Parameters
num:Object — The numeric value of the Number instance being created or a value
to be converted to a Number. The default value is 0 if num is
not specified.
|
| Number.toString(), Number.valueOf() |
public function toExponential(fractionDigits:uint):String
fractionDigits parameter.
Parameters
fractionDigits:uint — An integer between 0 and 20, inclusive, that represents the desired number of decimal places.
|
String |
toExponential(2) returns a string in
exponential notation.
var num:Number = 315003; trace(num.toExponential(2)); // Output: 3.15e+5
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
|
public function toFixed(fractionDigits:uint):String
fractionDigits parameter.
The valid range for the fractionDigits parameter is from 0 to 20.
Specifying a value outside this range throws an exception.
Parameters
fractionDigits:uint — An integer between 0 and 20, inclusive, that represents the desired number of decimal places.
|
String |
toFixed(3) returns a string that rounds
to three decimal places.
var num:Number = 7.31343; trace(num.toFixed(3)); // Output: 7.313
toFixed(2) returns a string that adds
trailing zeroes.
var num:Number = 4; trace(num.toFixed(2)); // Output: 4.00
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
|
public function toPrecision(precision:uint):String
precision parameter.
Parameters
precision:uint — An integer between 1 and 21, inclusive, that represents the desired number of digits to represent in the resulting string.
|
String |
toPrecision(3) returns a string with
only three digits. The string is in fixed-point notation because exponential notation is not required.
var num:Number = 31.570; trace(num.toPrecision(3)); // Output: 31.5
toPrecision(3) returns a string with
only three digits. The string is in exponential notation because the resulting number does not
contain enough digits for fixed-point notation.
var num:Number = 4000; trace(num.toPrecision(3)); // Output: 4.00e+3
RangeError — Throws an exception if the precision argument is outside the range 1 to 21.
|
public function toString(radix:Number = 10):String
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 (default = 10) — 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.
|
String —
The numeric representation of this Number as a string.
|
public function valueOf():Number
Number —
The primitive type value of this Number.
|
package {
import flash.display.Sprite;
public class NumberExample extends Sprite {
public function NumberExample() {
var num:Number = new Number(10.456345);
var str:String = num.toFixed(2);
trace(num); // 10.456345
trace(str); // 10.46
}
}
}