Mad*_*bar 5 java double parsing
在我的项目中,我从api获取字符串值,需要将double值传递给另一个api.当我尝试从字符串值解析为double时,我没有得到原始数据.
这是代码.
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)));
Run Code Online (Sandbox Code Playgroud)
输出是
11352721345377306.00
11352721346734308.00
11352721346734308.00
11352721346734308.00
Run Code Online (Sandbox Code Playgroud)
什么地方出了错?解析有什么问题吗?我怎样才能获得原始价值.
编辑:不使用十进制格式:
1.1352721345377306E16
1.1352721346734308E16
1.1352721346734308E16
1.1352721346734308E16
Run Code Online (Sandbox Code Playgroud)
您无法获得原始值.请参阅此Java的浮点(Im)精度.
| 归档时间: |
|
| 查看次数: |
2421 次 |
| 最近记录: |