Converting string to double always gives me wrong representation

Converting string to double always gives me wrong representation

I want to convert this string "0.00071942446044" to double by using Double.parsedouble method but it always gives this answer 7.1942446044E-4

Is there any idea to convert it to double but keeping the same number as it is in the string?

Although both numbers are exactly the same, you could use DecimalFormat to manipulate the format in a way you like, only for presentation purpose. Here is an example:

String s = "0.00071942446044";

Double d = Double.parseDouble(s);
DecimalFormat df = new DecimalFormat("#.##############");

System.out.println("double: " + d);
System.out.println("formatted: " + df.format(d)); 

The out is:

double: 7.1942446044E-4
formatted: 0.00071942446044

Note that the number of # after decimal point is exactly the same as your example.

You can use new BigDecimal(myString), this is not the same but will keep the same representation. It provides API for doing different math, but is slower than doing arithmetical operations with doubles.

.
.
.
.