The doubleValue() method returns the value of this Integer as double after performing widening primitive conversion.
Hierarchy:
java.lang Package -> Integer Class -> doubleValue() Method
Syntax of doubleValue() method
public double doubleValue()
doubleValue() Parameters
NA
doubleValue() Return Value
- A double data type value equivalent to the value of this Integer object numerically.
Supported java versions: Java 1.2 and onwards.
Example 1
public class JavaExample { public static void main(String[] args) { Integer i = new Integer("55"); Integer i2 = new Integer(97); double d = i.doubleValue(); double d2 = i2.doubleValue(); System.out.println("Value of Integer i as double: "+d); System.out.println("Value of Integer i2 as double: "+d2); } }
Output:
Example 2
public class JavaExample { public static void main(String[] args) { int num = 100; //primitive int Integer i = new Integer(num); //int to Integer object double d = i.doubleValue(); System.out.println("Value of num as double: "+d); } }
Output:
Example 3
import java.util.Scanner; public class JavaExample{ public static void main(String[] args){ Integer i; Scanner scan = new Scanner(System.in); System.out.print("Enter first int number: "); i = scan.nextInt(); double val = i.doubleValue(); System.out.println("Entered value as double: "+val); } }
Output: