W3docs

I need to convert an int variable to double

To convert an int to a double, you can use the doubleValue() method of the Integer class.

To convert an int to a double, you can use explicit casting or rely on Java's implicit widening conversion. When working with primitive types, casting is the standard approach.

For example:

int i = 5;
double d = (double) i;  // Explicit cast

Java also supports implicit widening conversion, where the int is automatically promoted to a double:

int i = 5;
double d = i;  // Automatic widening conversion

To convert a double back to an int, use explicit casting. Note that casting a double to an int truncates the decimal portion:

double d = 5.5;
int i = (int) d;  // Truncates to 5