New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs
See the Tutorial List

Java Long floatValue() Method

Java floatValue() method belongs to the Long class of the java.lang package. This method returns the floating equivalent of the Long after a widening primitive conversion(Conversion of a lower data type into a higher data type).

In short, this method is used to convert a Long object into a primitive float value.


public float floatValue()  


No parameter is passed in this method.


The float equivalent of the Long object that is created after conversion.

Example 1:

Here, using the floatValue() method, the Long object is converted into its float equivalent.

import java.lang.Long;

public class StudyTonight
    public static void main(String[] args) 
        //converting Long object into float
        Long x = 65L;
        float i = x.floatValue();
        Long y = 90L;  
        float d = y.floatValue();  


Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent float value.

import java.util.Scanner;  

public class StudyTonight
    public static void main(String[] args) 
            System.out.print("Enter the value to be converted : ");  
            Scanner sc = new Scanner(;  
            long i = sc.nextLong();  
            Long n = i ;  
            float val = n.floatValue();  //converting Long object into float
            System.out.println("Float Value is: " + val);  
        catch(Exception e)
            System.out.println("not a valid long"); 

Enter the value to be converted : 75
Float Value is: 75.0
Enter the value to be converted : 0x665
not a valid long

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.