Is there any way to convert a Long
data type to Double
or double
?
For example, I need to convert 15552451L
to a
As already mentioned, you can simply cast long to double. But be careful with long to double conversion because long to double is a narrowing conversion in java.
Conversion from type double to type long requires a nontrivial translation from a 64-bit floating-point value to the 64-bit integer representation. Depending on the actual run-time value, information may be lost.
e.g. following program will print 1 not 0
long number = 499999999000000001L;
double converted = (double) number;
System.out.println( number - (long) converted);