Is there any way to convert a Long
data type to Double
or double
?
For example, I need to convert 15552451L
to a double
data type.
Convert long to double Using the doubleValue() Method in Java. If you have a long object, you can simply use the doubleValue() method of the Long class to get a double type value. This method does not take any argument but returns a double after converting a long value.
There are a couple of ways to convert a double value to a long value in Java e.g. you can simply cast a double value to long or you can wrap a double value into a Double object and call it's longValue() method, or using Math. round() method to round floating-point value to the nearest integer.
Using Type Casting Let's check a straightforward way to cast the double to long using the cast operator: Assert. assertEquals(9999, (long) 9999.999); Applying the (long) cast operator on a double value 9999.999 results in 9999.
You could simply do :
double d = (double)15552451L;
Or you could get double from Long object as :
Long l = new Long(15552451L); double d = l.doubleValue();
Simple casting?
double d = (double)15552451L;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With