Java.lang.Float Class

Java Float Class

The Float class in the Java.lang package i.e. Java.lang.Float encapsulates a value of primitive type float in an object. A single field of type float is included in a Float object.

This class also has methods for converting a float to a String and a String to a float, as well as additional constants and methods that are handy when working with floats.

Class declaration

The declaration of java.lang.Float class is:

public final class Float
  extends Number
    implements Comparable<Float>

Fields

 

S.N Fields & Description
1. static int BYTES
The number of bytes used to represent a float value.
2. static int MAX_EXPONENT
Maximum exponent a finite float variable may have.
3. static float MAX_VALUE
A constant holding the largest positive finite value of type float, (2-2-23)·2127.
4. static int MIN_EXPONENT
Minimum exponent a normalized float variable may have.
5. static float MIN_NORMAL
A constant holding the smallest positive normal value of type float, 2-126.
6. static float MIN_VALUE
A constant holding the smallest positive nonzero value of type float, 2-149.
7. static float NaN
A constant holding a Not-a-Number (NaN) value of type float.
8. static float NEGATIVE_INFINITY
A constant holding the negative infinity of type float.
9. static float POSITIVE_INFINITY
A constant holding the positive infinity of type float.
10. static int SIZE
The number of bits used to represent a float value.
11. static Class<Float> TYPE
The Class instance representing the primitive type float.

java.lang.Float Methods

The java.lang.Float class has a number of methods which are listed below:

Member Methods

 

S.N Methods & Description
1. byte byteValue()
Returns the value of this Float as a byte after a narrowing primitive conversion.
2. static int compare(float f1, float f2)
Compares the two specified float values.
3. int compareTo(Float anotherFloat)
Compares two Float objects numerically.
4. double doubleValue()
Returns the value of this Float as a double after a widening primitive conversion.
5. boolean equals(Object obj)
Compares this object against the specified object.
6. static int floatToIntBits(float value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout.
7. static int floatToRawIntBits(float value)
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.
8. float floatValue()
Returns the float value of this Float object.
9. int hashCode()
Returns a hash code for this Float object.
10. static int hashCode(float value)
Returns a hash code for a float value; compatible with Float.hashCode().
11. static float intBitsToFloat(int bits)
Returns the float value corresponding to a given bit representation.
12. int intValue()
Returns the value of this Float as an int after a narrowing primitive conversion.
13. static boolean isFinite(float f)
Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).
14. boolean isInfinite()
Returns true if this Float value is infinitely large in magnitude, false otherwise.
15. static boolean isInfinite(float v)
Returns true if the specified number is infinitely large in magnitude, false otherwise.
16. boolean isNaN()
Returns true if this Float value is a Not-a-Number (NaN), false otherwise.
17. static boolean isNaN(float v)
Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
18. long longValue()
Returns value of this Float as a long after a narrowing primitive conversion.
19. static float max(float a, float b)
Returns the greater of two float values as if by calling Math.max.
20. static float min(float a, float b)
Returns the smaller of two float values as if by calling Math.min.
21. static float parseFloat(String s)
Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.
22. short shortValue()
Returns the value of this Float as a short after a narrowing primitive conversion.
23. static float sum(float a, float b)
Adds two float values together as per the + operator.
24. static String toHexString(float f)
Returns a hexadecimal string representation of the float argument.
25. String toString()
Returns a string representation of this Float object.
26. static String toString(float f)
Returns a string representation of the float argument.
27. static Float valueOf(float f)
Returns a Float instance representing the specified float value.
28. static Float valueOf(String s)
Returns a Float object holding the float value represented by the argument string s.

Methods inherited

This class inherits the methods of the following class:

  • java.lang.Object
  • java.lang.Number

 

To open the online compiler click here.

 

Also Read: Java – While Loop

Leave a Reply

Your email address will not be published. Required fields are marked *