Integer floatValue() Method in Java
Last Updated :
03 May, 2022
floatValue() method of Integer class present inside java.lang package is used to convert the value of the given Integer to a float type after a widening primitive conversion which in general is mostly applicable when we want to truncate or rounding-off the integer value. The package view is as follows:
--> java.lang Package
--> Integer Class
--> floatValue() Method
Syntax:
public float floatValue()
Return Type: A numeric value represented by this object after converting it to type float.
Note: This method is workable when it is supported by java version 1.2 or onwards, so make sure to update java version if running on older(introductory) java versions.
Example 1:
java
import java.lang.Integer;
class GFG {
public static void main(String args[])
{
Integer a = new Integer( 28 );
float b = a.floatValue();
System.out.println(b);
}
}
|
Output:
Example 2:
Java
import java.lang.Integer;
class GFG {
public static void main(String args[])
{
Integer a = new Integer( 20 );
float b = a.floatValue();
System.out.println(b);
}
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...