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.
For example:
int i = 5;
double d = i; // This will automatically convert the int to a double
Alternatively, you can use the Double.valueOf()
method to explicitly convert an int
to a double
:
int i = 5;
double d = Double.valueOf(i);
You can also use the intValue()
method of the Double
class to convert a double
back to an int
.
For example:
double d = 5.5;
int i = d.intValue(); // This will convert the double to an int and truncate any decimal values