In my project I am getting a string values from an api and need to pass double values to another api. When I try to parse from string values to double I am not getting the original data.
Here is the code.
String l1="11352721345377306";
String l2="11352721346734307";
String l3="11352721346734308";
String l4="11352721346734309";
DecimalFormat df = new DecimalFormat(".00");
System.out.println(df.format(Double.parseDouble(l1)));
System.out.println(df.format(Double.parseDouble(l2)));
System.out.println(df.format(Double.parseDouble(l3)));
System.out.println(df.format(Double.parseDouble(l4)));
The output is
11352721345377306.00
11352721346734308.00
11352721346734308.00
11352721346734308.00
What went wrong? Is there any problem with parsing? How can i get the original values back.?
Edit: Without using Decimal Format:
1.1352721345377306E16
1.1352721346734308E16
1.1352721346734308E16
1.1352721346734308E16
You can't get original values back. Refer this Java's Floating-Point (Im)Precision.
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