Package | Top Level |
Class | public final class Number |
Inheritance | Number Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
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 runtimes handle int and uint data types 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).
More examples
Related API Elements
Method | Defined By | ||
---|---|---|---|
Creates a Number object 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 the string representation of this object, formatted according to locale-specific conventions. | Object | ||
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 |
Constant | 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 |
Number | () | Constructor |
public function Number(num:Object)
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
Creates a Number object 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.
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. Using the constructor without specifying a num parameter is not
the same as declaring a variable of type Number with no value assigned (such as var myNumber:Number ), which
defaults to NaN . A number with no value assigned is undefined and the equivalent of
new Number(undefined) .
|
More examples
Related API Elements
toExponential | () | method |
AS3 function toExponential(fractionDigits:uint):String
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0, Flash Lite 4 |
Returns a string representation of the number in exponential notation. The string contains
one digit before the decimal point and up to 20 digits after the decimal point, as
specified by the fractionDigits
parameter.
Parameters
fractionDigits:uint — An integer between 0 and 20, inclusive, that represents the desired number of decimal places.
|
String |
Throws
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
|
Example ( How to use this example )
toExponential(2)
returns a string in
exponential notation.
var num:Number = 315003; trace(num.toExponential(2)); // 3.15e+5
toFixed | () | method |
AS3 function toFixed(fractionDigits:uint):String
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0, Flash Lite 4 |
Returns a string representation of the number in fixed-point notation.
Fixed-point notation means that the string will contain a specific number of digits
after the decimal point, as specified in the 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 |
Throws
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
|
Example ( How to use this example )
toFixed(3)
returns a string that rounds
to three decimal places.
var num:Number = 7.31343; trace(num.toFixed(3)); // 7.313
toFixed(2)
returns a string that adds
trailing zeroes.
var num:Number = 4; trace(num.toFixed(2)); // 4.00
toPrecision | () | method |
AS3 function toPrecision(precision:uint):String
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 9, AIR 1.0, Flash Lite 4 |
Returns a string representation of the number either in exponential notation or in
fixed-point notation. The string will contain the number of digits specified in the
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 |
Throws
RangeError — Throws an exception if the precision argument is outside the range 1 to 21.
|
Example ( How to use this example )
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)); // 31.6
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)); // 4.00e+3
toString | () | method |
AS3 function toString(radix:Number = 10):String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
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 (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 the Number object as a string.
|
valueOf | () | method |
MAX_VALUE | Constant |
public static const MAX_VALUE:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
The largest representable number (double-precision IEEE-754). This number is approximately 1.79e+308.
MIN_VALUE | Constant |
public static const MIN_VALUE:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
The smallest representable non-negative, non-zero, number (double-precision IEEE-754). This number is
approximately 5e-324. The smallest representable number overall is actually -Number.MAX_VALUE
.
NaN | Constant |
public static const NaN:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
The IEEE-754 value representing Not a Number (NaN
).
Related API Elements
NEGATIVE_INFINITY | Constant |
public static const NEGATIVE_INFINITY:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
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.
POSITIVE_INFINITY | Constant |
public static const POSITIVE_INFINITY:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 |
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.
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 } } }
Mon Nov 28 2011, 06:48 AM -08:00