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.
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