Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Float

public final class Float
extends Number implements Comparable<Float>

java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Float


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) * 2127.

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.

Inherited methods

From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

MAX_EXPONENT

Added in API level 9
int MAX_EXPONENT

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)

MAX_VALUE

Added in API level 1
float MAX_VALUE

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

Constant Value: 3.4028235E38

MIN_EXPONENT

Added in API level 9
int MIN_EXPONENT

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)

MIN_NORMAL

Added in API level 9
float MIN_NORMAL

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

Constant Value: 1.17549435E-38

MIN_VALUE

Added in API level 1
float MIN_VALUE

Constant for the minimum float value, 2-149.

Constant Value: 1.4E-45

NEGATIVE_INFINITY

Added in API level 1
float NEGATIVE_INFINITY

Constant for the negative infinity value of the float type.

Constant Value: -Infinity

NaN

Added in API level 1
float NaN

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

Constant Value: NaN

POSITIVE_INFINITY

Added in API level 1
float POSITIVE_INFINITY

Constant for the positive infinity value of the float type.

Constant Value: Infinity

SIZE

Added in API level 1
int SIZE

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

Constant Value: 32 (0x00000020)

Fields

TYPE

Added in API level 1
Class<Float> TYPE

The Class object that represents the primitive type float.

Public constructors

Float

Added in API level 1
Float (float value)

Constructs a new Float with the specified primitive float value.

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

Float

Added in API level 1
Float (double value)

Constructs a new Float with the specified primitive double value.

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

Float

Added in API level 1
Float (String string)

Constructs a new Float from the specified string.

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

See also:

Public methods

byteValue

Added in API level 1
byte byteValue ()

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

Returns
byte the primitive byte value of this object.

compare

Added in API level 1
int compare (float float1, 
                float float2)

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 float: the first value to compare.
float2 float: the second value to compare.
Returns
int 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.

compareTo

Added in API level 1
int compareTo (Float object)

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 Float: the float object to compare this object to.
Returns
int 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:

doubleValue

Added in API level 1
double doubleValue ()

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

Returns
double the primitive double value of this object.

equals

Added in API level 1
boolean equals (Object object)

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 NaNs compare equal by this method.

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

floatToIntBits

Added in API level 1
int floatToIntBits (float value)

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)).

Parameters
value float
Returns
int

floatToRawIntBits

Added in API level 1
int floatToRawIntBits (float value)

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)).

Parameters
value float
Returns
int

floatValue

Added in API level 1
float floatValue ()

Gets the primitive value of this float.

Returns
float this object's primitive value.

hashCode

Added in API level 1
int hashCode ()

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
int this object's hash code.

intBitsToFloat

Added in API level 1
float intBitsToFloat (int bits)

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

Parameters
bits int
Returns
float

intValue

Added in API level 1
int intValue ()

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

Returns
int the primitive int value of this object.

isInfinite

Added in API level 1
boolean isInfinite (float f)

Indicates whether the specified float represents an infinite value.

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

isInfinite

Added in API level 1
boolean isInfinite ()

Indicates whether this object represents an infinite value.

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

isNaN

Added in API level 1
boolean isNaN ()

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

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

isNaN

Added in API level 1
boolean isNaN (float f)

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

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

longValue

Added in API level 1
long longValue ()

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

Returns
long the primitive long value of this object.

parseFloat

Added in API level 1
float parseFloat (String string)

Parses the specified string as a float value.

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

See also:

shortValue

Added in API level 1
short shortValue ()

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

Returns
short the primitive short value of this object.

toHexString

Added in API level 1
String toHexString (float f)

Converts the specified float into its hexadecimal string representation.

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

toString

Added in API level 1
String toString ()

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
String a printable representation of this object.

toString

Added in API level 1
String toString (float f)

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

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

valueOf

Added in API level 1
Float valueOf (String string)

Parses the specified string as a float value.

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

See also:

valueOf

Added in API level 1
Float valueOf (float f)

Returns a Float instance for the specified float value.

Parameters
f float: the float value to store in the instance.
Returns
Float a Float instance containing f.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.