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

Java Float doubleValue() Method

Java doubleValue() method belongs to the Float class. This method returns the double equivalent of the Float 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 Float object into a double value.

Syntax:

public double doubleValue()  

Parameter:

No parameter is passed in this method.

Returns:

The numerical equivalent of the object of a double type that is created after conversion.

Example 1:

Here, using the doubleValue() function and float values are converted into its numerical double equivalent.

import java.lang.Float;

public class StudyTonight
{  
    public static void main(String[] args) 
      {  
        //converting Float object into double
          Float x = 99.12f;
          double i=x.doubleValue();
          System.out.println("Equivalent double value is " +i);
          
          
          Float y = 23.23f;  
          double d = y.doubleValue();  
          System.out.println("Equivalent double value is " +d);
      }  
}  


Equivalent double value is 99.12000274658203
Equivalent double value is 23.229999542236328

Example 2:

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

import java.util.Scanner;  
public class StudyTonight
{  
    public static void main(String[] args) 
    {  
         try
           {
              System.out.print("Enter the value to be converted : ");  
              Scanner sc = new Scanner(System.in);  
              float i = sc.nextFloat();  
              Float f = i ;  
              double val = f.doubleValue();  
              System.out.println("Double Value is: " + val);  
           }
         catch(Exception e)
           {
              System.out.println("not a valid float value"); 
           }
    }
}


Enter the value to be converted : 734.86
Double Value is: 734.8599853515625
************************************************
Enter the value to be converted : 0x00.5
not a valid float value

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.