Q:

Java Convert int to double

belongs to collection: Java Conversion Programs

0

We can convert int to double in java using assignment operator. There is nothing to do extra because lower type can be converted to higher type implicitly.

It is also known as implicit type casting or type promotion.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java int to double Example

Let's see the simple code to convert int to double in java.

public class IntToDoubleExample1{  
public static void main(String args[]){  
int i=200;  
double d=i;  
System.out.println(d);  
}}  

 

Output:

200.0

 

Java int to Double Example

We can convert int value to Double object by instantiating Double class or calling Double.valueOf() method.

Let's see the simple code to convert int to Double in java.

public class IntToDoubleExample2{  
public static void main(String args[]){  
int i=100;  
Double d= new Double(i);//first way  
Double d2=Double.valueOf(i);//second way  
System.out.println(d);  
System.out.println(d2);  
}}  

 

Output:

100.0
100.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Convert double to int... >>
<< Java Convert long to int...