To convert
int
to double
in Java, just assign int
to a double
variable.Assignment
Java implicitly converts int
to double
during assignment.
int myInt = 3;
double myDouble = myInt;
System.out.println(myDouble); // 3.0
Casting
You can also cast it in-place, if you don't want to make a new variable.
int myInt = 3;
System.out.println((double)myInt); // 3.0