Thursday, October 9, 2025
HomeLanguagesJavaFloat floatValue() in Java with examples

Float floatValue() in Java with examples

The floatValue() method in Float Class is a built-in function in java that returns the value specified by the calling object as float after type casting.

Syntax:  

public float floatValue()

Return Value: It returns the value of FloatObject as float.

Below programs illustrate floatValue() method in Java:

Program 1:  

Java




// Java code to demonstrate
// Float floatValue() method
 
class GFG {
    public static void main(String[] args)
    {
 
        // Float value
        Float a = 17.47f;
 
        // wrapping the Float value
        // in the wrapper class Float
        Float b = new Float(a);
 
        // floatValue of the Float Object
        float output = b.floatValue();
 
        // prfloating the output
        System.out.println("Float value of "
                           + b + " is : " + output);
    }
}


Output: 

Float value of 17.47 is : 17.47




 

Program 2:

Java




// Java code to demonstrate
// Float floatValue() method
 
class GFG {
    public static void main(String[] args)
    {
 
        String value = "54.1";
 
        // wrapping the Float value
        // in the wrapper class Float
        Float b = new Float(value);
 
        // floatValue of the Float Object
        float output = b.floatValue();
 
        // prfloating the output
        System.out.println("Float value of "
                           + b + " is : " + output);
    }
}


Output: 

Float value of 54.1 is : 54.1




 

Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#floatValue()
 

RELATED ARTICLES

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6790 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS