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
float MAX_VALUE Constant for the maximum float value, (2 - 2-23) * 2127.
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.
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)
Compares this instance with the specified object and indicates if they are equal.
static int floatToIntBits(float value)
Converts the specified float value to a binary representation conforming to the IEEE 754 floating-point single precision bit layout.
static int floatToRawIntBits(float value)
Converts the specified float value to a binary representation conforming to the IEEE 754 floating-point single precision bit layout.
float floatValue()
Gets the primitive value of this float.
int hashCode()
Returns an integer hash code for this object.
static float intBitsToFloat(int bits)
Converts the specified IEEE 754 floating-point single precision bit pattern to a Java float value.
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.
static boolean isNaN(float f)
Indicates whether the specified float is a Not-a-Number (NaN) value.
boolean isNaN()
Indicates whether this object 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.
static String toString(float f)
Returns a string containing a concise, human-readable description of the specified float value.
String toString()
Returns a string containing a concise, human-readable description of this object.
static Float valueOf(float f)
Returns a Float instance for the specified float value.
static Float valueOf(String string)
Parses the specified string as a float value.
[Expand]
Inherited Methods
From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

public static final float MAX_VALUE

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

Constant Value: 3.4028235E38

public static final float MIN_VALUE

Constant for the minimum float value, 2-149.

Constant Value: 1.4E-45

public static final float NEGATIVE_INFINITY

Constant for the Negative Infinity value of the float type.

Constant Value: -Infinity

public static final float NaN

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

Constant Value: NaN

public static final float POSITIVE_INFINITY

Constant for the Positive Infinity value of the float type.

Constant Value: Infinity

public static final int SIZE

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

Constant Value: 32 (0x00000020)

public static final Class<Float> TYPE

The Class object that represents the primitive type float.

Public Constructors

public Float (float value)

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)

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)

Constructs a new Float from the specified string.

Parameters
string the string representation of a float value.
Throws
NumberFormatException if string can not be decoded into a float value.

Public Methods

public 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
  • the primitive byte value of this object.

public static 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 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)

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

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

Returns
  • the primitive double value of this object.

public boolean equals (Object object)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, object must be an instance of Float and have the same float value as this object.

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)

Converts the specified float value to a binary representation conforming to the IEEE 754 floating-point single precision bit layout. All Not-a-Number (NaN) values are converted to a single NaN representation (0x7ff8000000000000L).

Parameters
value the float value to convert.
Returns
  • the IEEE 754 floating-point single precision representation of value.

public static int floatToRawIntBits (float value)

Converts the specified float value to a binary representation conforming to the IEEE 754 floating-point single precision bit layout. Not-a-Number (NaN) values are preserved.

Parameters
value the float value to convert.
Returns
  • the IEEE 754 floating-point single precision representation of value.

public float floatValue ()

Gets the primitive value of this float.

Returns
  • this object's primitive value.

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

Returns
  • this object's hash code.

public static float intBitsToFloat (int bits)

Converts the specified IEEE 754 floating-point single precision bit pattern to a Java float value.

Parameters
bits the IEEE 754 floating-point single precision representation of a float value.
Returns
  • the float value converted from bits.

public 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
  • the primitive int value of this object.

public static boolean isInfinite (float f)

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

Indicates whether this object represents an infinite value.

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

public static boolean isNaN (float f)

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 boolean isNaN ()

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 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
  • the primitive long value of this object.

public static float parseFloat (String string)

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 is null, has a length of zero or can not be parsed as a float value.

public 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
  • the primitive short value of this object.

public static String toHexString (float f)

Converts the specified float into its hexadecimal string representation.

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

public static String toString (float f)

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 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 simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

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

Returns
  • a printable representation of this object.

public static Float valueOf (float f)

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.

public static Float valueOf (String string)

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 is null, has a length of zero or can not be parsed as a float value.