Saturday, June 20, 2026
HomeLanguagesJavaInteger floatValue() Method in Java

Integer floatValue() Method in Java

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




// Java Program to Demonstrate floatValue() Method
// of Integer Class
 
// Importing required classes
import java.lang.Integer;
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String args[])
    {
 
        // Creating a custom integer by
        // creating object of Integer class
        Integer a = new Integer(28);
 
        // Converting Integer number to float value
        // using floatValue() method
        float b = a.floatValue();
 
        // Printing the float value
        System.out.println(b);
    }
}


Output:

 

Example 2:

Java




// Java Program to Demonstrate Working of floatValue()
// Method of Integer Class
 
// Importing required class
import java.lang.Integer;
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String args[])
    {
        // Creating a custom integer value by
        // declaring object of Integer Class
        Integer a = new Integer(20);
 
        // Convert Integer number to float value
        // using floatValue() method
        float b = a.floatValue();
 
        // Printing the float value on console
        System.out.println(b);
    }
}


Output:

 

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6899 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS