Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion from Long to Double in Java

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.

like image 752
Harry Avatar asked Sep 16 '10 08:09

Harry


People also ask

Can we convert long to double in Java?

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.

Can you convert Doubles long?

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.

How do you convert double to long value?

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.


2 Answers

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(); 
like image 93
YoK Avatar answered Oct 16 '22 02:10

YoK


Simple casting?

double d = (double)15552451L; 
like image 35
Jim Brissom Avatar answered Oct 16 '22 02:10

Jim Brissom