Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public final class

Float

extends Number
implements Comparable <T>
java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Float

Class Overview

The wrapper for the primitive type float .

See Also

Summary

Constants
int MAX_EXPONENT Maximum base-2 exponent that a finite value of the float type may have.
float MAX_VALUE Constant for the maximum float value, (2 - 2 -23 ) * 2 127 .
int MIN_EXPONENT Minimum base-2 exponent that a normal value of the float type may have.
float MIN_NORMAL Constant for the smallest positive normal value of the float type.
float MIN_VALUE Constant for the minimum float value, 2 -149 .
float NEGATIVE_INFINITY Constant for the negative infinity value of the float type.
float NaN Constant for the Not-a-Number (NaN) value of the float type.
float POSITIVE_INFINITY Constant for the positive infinity value of the float type.
int SIZE Constant for the number of bits needed to represent a float in two's complement form.
Fields
public static final Class < Float > TYPE The Class object that represents the primitive type float .
Public Constructors
Float (float value)
Constructs a new Float with the specified primitive float value.
Float (double value)
Constructs a new Float with the specified primitive double value.
Float ( String string)
Constructs a new Float from the specified string.
Public Methods
byte byteValue ()
Returns this object's value as a byte.
static int compare (float float1, float float2)
Compares the two specified float values.
int compareTo ( Float object)
Compares this object to the specified float object to determine their relative order.
double doubleValue ()
Returns this object's value as a double.
boolean equals ( Object object)
Tests this double for equality with object .
static int floatToIntBits (float value)
Returns an integer corresponding to the bits of the given IEEE 754 single precision float value .
static int floatToRawIntBits (float value)
Returns an integer corresponding to the bits of the given IEEE 754 single precision float value .
float floatValue ()
Gets the primitive value of this float.
int hashCode ()
Returns an integer hash code for this object.
static float intBitsToFloat (int bits)
Returns the IEEE 754 single precision float corresponding to the given bits .
int intValue ()
Returns this object's value as an int.
static boolean isInfinite (float f)
Indicates whether the specified float represents an infinite value.
boolean isInfinite ()
Indicates whether this object represents an infinite value.
boolean isNaN ()
Indicates whether this object is a Not-a-Number (NaN) value.
static boolean isNaN (float f)
Indicates whether the specified float is a Not-a-Number (NaN) value.
long longValue ()
Returns this object's value as a long.
static float parseFloat ( String string)
Parses the specified string as a float value.
short shortValue ()
Returns this object's value as a short.
static String toHexString (float f)
Converts the specified float into its hexadecimal string representation.
String toString ()
Returns a string containing a concise, human-readable description of this object.
static String toString (float f)
Returns a string containing a concise, human-readable description of the specified float value.
static Float valueOf ( String string)
Parses the specified string as a float value.
static Float valueOf (float f)
Returns a Float instance for the specified float value.
[Expand]
Inherited Methods
From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

public static final int MAX_EXPONENT

Added in API level 9

Maximum base-2 exponent that a finite value of the float type may have. Equal to Math.getExponent(Float.MAX_VALUE) .

Constant Value: 127 (0x0000007f)

public static final float MAX_VALUE

Added in API level 1

Constant for the maximum float value, (2 - 2 -23 ) * 2 127 .

Constant Value: 3.4028235E38

public static final int MIN_EXPONENT

Added in API level 9

Minimum base-2 exponent that a normal value of the float type may have. Equal to Math.getExponent(Float.MIN_NORMAL) .

Constant Value: -126 (0xffffff82)

public static final float MIN_NORMAL

Added in API level 9

Constant for the smallest positive normal value of the float type.

Constant Value: 1.17549435E-38

public static final float MIN_VALUE

Added in API level 1

Constant for the minimum float value, 2 -149 .

Constant Value: 1.4E-45

public static final float NEGATIVE_INFINITY

Added in API level 1

Constant for the negative infinity value of the float type.

Constant Value: -Infinity

public static final float NaN

Added in API level 1

Constant for the Not-a-Number (NaN) value of the float type.

Constant Value: NaN

public static final float POSITIVE_INFINITY

Added in API level 1

Constant for the positive infinity value of the float type.

Constant Value: Infinity

public static final int SIZE

Added in API level 1

Constant for the number of bits needed to represent a float in two's complement form.

Constant Value: 32 (0x00000020)

Fields

public static final Class < Float > TYPE

Added in API level 1

The Class object that represents the primitive type float .

Public Constructors

public Float (float value)

Added in API level 1

Constructs a new Float with the specified primitive float value.

Parameters
value the primitive float value to store in the new instance.

public Float (double value)

Added in API level 1

Constructs a new Float with the specified primitive double value.

Parameters
value the primitive double value to store in the new instance.

public Float ( String string)

Added in API level 1

Constructs a new Float from the specified string.

Parameters
string the string representation of a float value.
Throws
NumberFormatException if string can not be parsed as a float value.

Public Methods

public byte byteValue ()

Added in API level 1

Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.

Returns
  • the primitive byte value of this object.

public static int compare (float float1, float float2)

Added in API level 1

Compares the two specified float values. There are two special cases:

  • Float.NaN is equal to Float.NaN and it is greater than any other float value, including Float.POSITIVE_INFINITY ;
  • +0.0f is greater than -0.0f

Parameters
float1 the first value to compare.
float2 the second value to compare.
Returns
  • a negative value if float1 is less than float2 ; 0 if float1 and float2 are equal; a positive value if float1 is greater than float2 .

public int compareTo ( Float object)

Added in API level 1

Compares this object to the specified float object to determine their relative order. There are two special cases:

  • Float.NaN is equal to Float.NaN and it is greater than any other float value, including Float.POSITIVE_INFINITY ;
  • +0.0f is greater than -0.0f

Parameters
object the float object to compare this object to.
Returns
  • a negative value if the value of this float is less than the value of object ; 0 if the value of this float and the value of object are equal; a positive value if the value of this float is greater than the value of object .
See Also

public double doubleValue ()

Added in API level 1

Returns this object's value as a double. Might involve rounding.

Returns
  • the primitive double value of this object.

public boolean equals ( Object object)

Added in API level 1

Tests this double for equality with object . To be equal, object must be an instance of Float and floatToIntBits must give the same value for both objects.

Note that, unlike == , -0.0 and +0.0 compare unequal, and NaN s compare equal by this method.

Parameters
object the object to compare this float with.
Returns
  • true if the specified object is equal to this Float ; false otherwise.

public static int floatToIntBits (float value)

Added in API level 1

Returns an integer corresponding to the bits of the given IEEE 754 single precision float value . All Not-a-Number (NaN) values are converted to a single NaN representation ( 0x7fc00000 ) (compare to floatToRawIntBits(float) ).

public static int floatToRawIntBits (float value)

Added in API level 1

Returns an integer corresponding to the bits of the given IEEE 754 single precision float value . Not-a-Number (NaN) values are preserved (compare to floatToIntBits(float) ).

public float floatValue ()

Added in API level 1

Gets the primitive value of this float.

Returns
  • this object's primitive value.

public int hashCode ()

Added in API level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public static float intBitsToFloat (int bits)

Added in API level 1

Returns the IEEE 754 single precision float corresponding to the given bits .

public int intValue ()

Added in API level 1

Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.

Returns
  • the primitive int value of this object.

public static boolean isInfinite (float f)

Added in API level 1

Indicates whether the specified float represents an infinite value.

Parameters
f the float to check.
Returns
  • true if the value of f is positive or negative infinity; false otherwise.

public boolean isInfinite ()

Added in API level 1

Indicates whether this object represents an infinite value.

Returns
  • true if the value of this float is positive or negative infinity; false otherwise.

public boolean isNaN ()

Added in API level 1

Indicates whether this object is a Not-a-Number (NaN) value.

Returns
  • true if this float is Not-a-Number ; false if it is a (potentially infinite) float number.

public static boolean isNaN (float f)

Added in API level 1

Indicates whether the specified float is a Not-a-Number (NaN) value.

Parameters
f the float value to check.
Returns
  • true if f is Not-a-Number ; false if it is a (potentially infinite) float number.

public long longValue ()

Added in API level 1

Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.

Returns
  • the primitive long value of this object.

public static float parseFloat ( String string)

Added in API level 1

Parses the specified string as a float value.

Parameters
string the string representation of a float value.
Returns
  • the primitive float value represented by string .
Throws
NumberFormatException if string can not be parsed as a float value.

public short shortValue ()

Added in API level 1

Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.

Returns
  • the primitive short value of this object.

public static String toHexString (float f)

Added in API level 1

Converts the specified float into its hexadecimal string representation.

Parameters
f the float to convert.
Returns
  • the hexadecimal string representation of f .

public String toString ()

Added in API level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

          getClass().getName() + '@' + Integer.toHexString(hashCode())
         

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public static String toString (float f)

Added in API level 1

Returns a string containing a concise, human-readable description of the specified float value.

Parameters
f the float to convert to a string.
Returns
  • a printable representation of f .

public static Float valueOf ( String string)

Added in API level 1

Parses the specified string as a float value.

Parameters
string the string representation of a float value.
Returns
  • a Float instance containing the float value represented by string .
Throws
NumberFormatException if string can not be parsed as a float value.

public static Float valueOf (float f)

Added in API level 1

Returns a Float instance for the specified float value.

Parameters
f the float value to store in the instance.
Returns
  • a Float instance containing f .