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

Java Integer doubleValue() Method

Java doubleValue() Method belongs to the Integer class. This method returns the Double Equivalent of the Integer after a widening primitive conversion(Conversion of a lower data type into a higher data type).

In short, this method is used to convert an Integer 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 double type that is created after conversion.

Example 1:

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

import java.lang.Integer;

public class StudyTonight
{  
    public static void main(String[] args) 
      {  
        //converting integer object into double
          Integer x = 99;
          double i=x.doubleValue();
          System.out.println(i);
          
          
          Integer y = 23;  
          double d = y.doubleValue();  
          System.out.println(d);
      }  
}    


99.0
23.0

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);  
              int i = sc.nextInt();  
              Integer n = i ;  
              double val = n.doubleValue();  
              System.out.println("Double Value is: " + val);  
           }
         catch(Exception e)
           {
              System.out.println("not a valid integer"); 
           }
    }
}


Enter the value to be converted : 800
Double Value is: 800.0
*******************************************
Enter the value to be converted : 89f
not a valid integer

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.