Java.lang.Float Class

Java.lang.Float Class

Introduction

The java.lang.Float class wraps a value of primitive type float in an object. An object of type Float contains a single field whose type is float.

Class declaration

Following is the declaration for java.lang.Float class:

public final class Float
   extends Number
     implements Comparable<Float>

Field

Following are the fields for java.lang.Float class:

  • static int MAX_EXPONENT — This is Maximum exponent a finite float variable may have.
  • static float MAX_VALUE — This is a constant holding the largest positive finite value of type float, (2-2-23)·2127.
  • static int MIN_EXPONENT — This is minimum exponent a normalized float variable may have.
  • static float MIN_NORMAL — This is a constant holding the smallest positive normal value of type float, 2-126.
  • static float MIN_VALUE — This is a constant holding the smallest positive nonzero value of type float, 2-149.
  • static float NaN — This is a constant holding a Not-a-Number (NaN) value of type float.
  • static float NEGATIVE_INFINITY — This is a constant holding the negative infinity of type float.
  • static float POSITIVE_INFINITY — This is a constant holding the positive infinity of type float.
  • static int SIZE — This is the number of bits used to represent a float value.
  • static Class<Float> TYPE — This is the Class instance representing the primitive type float.

Class constructors

S.N.Constructor & Description
1Float(double value)

This constructs a newly allocated Float object that represents the argument converted to type float.

2Float(float value)

This constructs a newly allocated Float object that represents the primitive float argument.

3Float(String s)

This constructs a newly allocated Float object that represents the floating-point value of type float represented by the string.

Class methods

S.N.Method & Description
1byte byteValue()

This method returns the value of this Float as a byte (by casting to a byte).

2static int compare(float f1, float f2)

This method compares the two specified float values.

3int compareTo(Float anotherFloat)

This method compares two Float objects numerically.

4double doubleValue()

This method returns the double value of this Float object.

5boolean equals(Object obj)

This method compares this object against the specified object.

6static int floatToIntBits(float value)

This method returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout.

7static int floatToRawIntBits(float value)

This method returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout, preserving Not-a-Number (NaN) values.

8float floatValue()

This method returns the float value of this Float object.

9int hashCode()

This method returns a hash code for this Float object.

10static float intBitsToFloat(int bits)

This method returns the float value corresponding to a given bit representation.

11int intValue()

This method returns the value of this Float as an int (by casting to type int).

12boolean isInfinite()

This method returns true if this Float value is infinitely large in magnitude, false otherwise.

13static boolean isInfinite(float v)

This method returns true if the specified number is infinitely large in magnitude, false otherwise.

14boolean isNaN()

This method returns true if this Float value is a Not-a-Number (NaN), false otherwise.

15static boolean isNaN(float v)

This method returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

16long longValue()

This method returns value of this Float as a long (by casting to type long).

17static float parseFloat(String s)

This method returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.

18short shortValue()

This method returns the value of this Float as a short (by casting to a short).

19static String toHexString(float f)

This method returns a hexadecimal string representation of the float argument.

20String toString()

This method returns a string representation of this Float object.

21static String toString(float f)

This method returns a string representation of the float argument

22static Float valueOf(float f)

This method returns a Float instance representing the specified float value.

23static Float valueOf(String s)

This method returns a Float object holding the float value represented by the argument string s.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.