Package java.lang

Class Float

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAX_EXPONENT
      Maximum base-2 exponent that a finite value of the float type may have.
      static float MAX_VALUE
      Constant for the maximum float value, (2 - 2-23) * 2127.
      static int MIN_EXPONENT
      Minimum base-2 exponent that a normal value of the float type may have.
      static float MIN_NORMAL
      Constant for the smallest positive normal value of the float type.
      static float MIN_VALUE
      Constant for the minimum float value, 2-149.
      static float NaN
      Constant for the Not-a-Number (NaN) value of the float type.
      static float NEGATIVE_INFINITY
      Constant for the negative infinity value of the float type.
      static float POSITIVE_INFINITY
      Constant for the positive infinity value of the float type.
      static int SIZE
      Constant for the number of bits needed to represent a float in two's complement form.
    • Constructor Summary

      Constructors 
      Constructor Description
      Float​(double value)
      Constructs a new Float with the specified primitive double value.
      Float​(float value)
      Constructs a new Float with the specified primitive float value.
      Float​(String string)
      Constructs a new Float from the specified string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      float floatValue()
      Gets the primitive value of this float.
      int hashCode()
      Returns an integer hash code for this object.
      int intValue()
      Returns this object's value as an int.
      boolean isInfinite()
      Indicates whether this object represents an infinite value.
      static boolean isInfinite​(float f)
      Indicates whether the specified float 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.
      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​(float f)
      Returns a Float instance for the specified float value.
      static Float valueOf​(String string)  
    • Field Detail

      • MAX_VALUE

        public static final float MAX_VALUE
        Constant for the maximum float value, (2 - 2-23) * 2127.
        See Also:
        Constant Field Values
      • MIN_VALUE

        public static final float MIN_VALUE
        Constant for the minimum float value, 2-149.
        See Also:
        Constant Field Values
      • NaN

        public static final float NaN
        Constant for the Not-a-Number (NaN) value of the float type.
        See Also:
        Constant Field Values
      • POSITIVE_INFINITY

        public static final float POSITIVE_INFINITY
        Constant for the positive infinity value of the float type.
        See Also:
        Constant Field Values
      • NEGATIVE_INFINITY

        public static final float NEGATIVE_INFINITY
        Constant for the negative infinity value of the float type.
        See Also:
        Constant Field Values
      • MIN_NORMAL

        public static final float MIN_NORMAL
        Constant for the smallest positive normal value of the float type.
        Since:
        1.6
        See Also:
        Constant Field Values
      • MAX_EXPONENT

        public static final int MAX_EXPONENT
        Maximum base-2 exponent that a finite value of the float type may have. Equal to Math.getExponent(Float.MAX_VALUE).
        Since:
        1.6
        See Also:
        Constant Field Values
      • MIN_EXPONENT

        public static final int MIN_EXPONENT
        Minimum base-2 exponent that a normal value of the float type may have. Equal to Math.getExponent(Float.MIN_NORMAL).
        Since:
        1.6
        See Also:
        Constant Field Values
      • SIZE

        public static final int SIZE
        Constant for the number of bits needed to represent a float in two's complement form.
        Since:
        1.5
        See Also:
        Constant Field Values
    • Constructor Detail

      • Float

        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.
      • Float

        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.
    • Method Detail

      • parseFloat

        public static float parseFloat​(String string)
                                throws NumberFormatException
        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.
        Since:
        1.2
        See Also:
        valueOf(String)
      • compareTo

        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
        Specified by:
        compareTo in interface Comparable<Float>
        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.
        Since:
        1.2
        See Also:
        Comparable
      • compare

        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.
        Since:
        1.4
      • isInfinite

        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.
      • isInfinite

        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.
      • isNaN

        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.
      • isNaN

        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.
      • equals

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

        Overrides:
        equals in class Object
        Parameters:
        object - the object to compare this float with.
        Returns:
        true if the specified object is equal to this Float; false otherwise.
        See Also:
        Object.hashCode()
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.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.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • toString

        public String toString()
        Description copied from class: Object
        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.
        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • toString

        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.
      • valueOf

        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.
        Since:
        1.5
      • byteValue

        public byte byteValue()
        Description copied from class: Number
        Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.
        Overrides:
        byteValue in class Number
        Returns:
        the primitive byte value of this object.
      • shortValue

        public short shortValue()
        Description copied from class: Number
        Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.
        Overrides:
        shortValue in class Number
        Returns:
        the primitive short value of this object.
      • intValue

        public int intValue()
        Description copied from class: Number
        Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.
        Specified by:
        intValue in class Number
        Returns:
        the primitive int value of this object.
      • longValue

        public long longValue()
        Description copied from class: Number
        Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.
        Specified by:
        longValue in class Number
        Returns:
        the primitive long value of this object.
      • floatValue

        public float floatValue()
        Gets the primitive value of this float.
        Specified by:
        floatValue in class Number
        Returns:
        this object's primitive value.
      • doubleValue

        public double doubleValue()
        Description copied from class: Number
        Returns this object's value as a double. Might involve rounding.
        Specified by:
        doubleValue in class Number
        Returns:
        the primitive double value of this object.