PackageTop Level
Classpublic final class float
Inheritancefloat Inheritance Object

Language version: ActionScript 3.0
Runtime version: AIR 51.0

A data type representing an IEEE-754 single-precision floating-point number. You can manipulate primitive numeric values by using the methods and properties associated with the float class, as well as normal arithmetic operators.

Float values are stored as 32-bit values and are supported in ActionScript Byte Code version 47.16 and above. To use single-precision floating point functionality, you will need to compile your application using the AIR compiler version 3.0.0 or above (provided with AIR SDK 51.0), and the target AIR runtime would need to be AIR 51.0 or above.

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

The float data type adheres to the single-precision IEEE-754 standard.

The float data type is useful when you need to use floating-point values without needing the precision or using the memory associated with the double-precision Number type. This can be particularly useful when interacting with graphical systems such as the Stage3D APIs, where float-specific functions are now available for program constants and vertex buffers.

The default value of a variable typed as flat is NaN (Not a Number). To assign number values to a float variable, an 'f' character should be appended to the value - for example:

var floatVal:float = 1.23f;

Note that when a float value is converted into a String, the internal functionality will promote the single-precision value into a double-precision value which will then be converted into a string. Some precision changes may occur during this promotion/conversion process.

See also

int
uint
Number


Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
  
Creates a float object with the specified value.
float
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
toExponential(fractionDigits:uint):String
Returns a string representation of the float value in exponential notation.
float
  
toFixed(fractionDigits:uint):String
Returns a string representation of the float value in fixed-point notation.
float
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
  
toPrecision(precision:uint):String
Returns a string representation of the float value either in exponential notation or in fixed-point notation.
float
  
toString(radix:* = 10):String
Returns the string representation of the specified float object.
float
  
Returns the primitive value type of the specified float object.
float
Public Constants
 ConstantDefined by
  MAX_VALUE : float
[static] The largest representable number (single-precision IEEE-754).
float
  MIN_VALUE : float
[static] The smallest (closest to zero, not most negative) representable single-precision IEEE-754 number that does not compare equal to zero.
float
  NaN : float
[static] The single-precision IEEE-754 value representing Not a Number (NaN).
float
  NEGATIVE_INFINITY : float
[static] Specifies the single-precision IEEE-754 value representing negative infinity.
float
  POSITIVE_INFINITY : float
[static] Specifies the single-prevision IEEE-754 value representing positive infinity.
float
Constructor detail
float()constructor
public function float(num:Object)

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Creates a float object with the specified value. This constructor has the same effect as the float() public native function that converts an object of a different type to a primitive numeric value.

Parameters
num:Object
Method detail
toExponential()method
AS3 function toExponential(fractionDigits:uint):String

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Returns a string representation of the float value 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.

Returns
String

Throws
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
toFixed()method 
AS3 function toFixed(fractionDigits:uint):String

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Returns a string representation of the float value 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.

Returns
String

Throws
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20.
toPrecision()method 
AS3 function toPrecision(precision:uint):String

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Returns a string representation of the float value 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.

Returns
String

Throws
RangeError — Throws an exception if the precision argument is outside the range 1 to 21.
toString()method 
AS3 function toString(radix:* = 10):String

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Returns the string representation of the specified float object.

If the value of the float object is a decimal number without a leading zero (such as .4), float.toString() adds a leading zero (0.4).

Note that the conversion internally promotes the single-precision value into a double-precision value which is then converted to a string, hence the resulting precision may be higher than expected.

Parameters
radix:* (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.

Returns
String — The numeric representation of the float object as a string.
valueOf()method 
AS3 function valueOf():float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Returns the primitive value type of the specified float object.

Returns
float — The primitive type value of the float object.
Constant detail
MAX_VALUEconstant
public static const MAX_VALUE:float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

The largest representable number (single-precision IEEE-754). This number is approximately 3.4e38.

MIN_VALUEconstant 
public static const MIN_VALUE:float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

The smallest (closest to zero, not most negative) representable single-precision IEEE-754 number that does not compare equal to zero. On most platforms this number is approximately 1.4e-45.

Note: The absolute smallest representable number overall is -float.MAX_VALUE.

NaNconstant 
public static const NaN:float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

The single-precision IEEE-754 value representing Not a Number (NaN).

NEGATIVE_INFINITYconstant 
public static const NEGATIVE_INFINITY:float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Specifies the single-precision IEEE-754 value representing negative 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_INFINITYconstant 
public static const POSITIVE_INFINITY:float

Language version: ActionScript 3.0
Runtime version: AIR 51.0

Specifies the single-prevision IEEE-754 value representing positive 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.