当前位置: 代码迷 >> Java Web开发 >> Double.parseDouble("554546") * Double.parseDouble("0.05")=27727.300000000003 ,怎么减少误差
  详细解决方案

Double.parseDouble("554546") * Double.parseDouble("0.05")=27727.300000000003 ,怎么减少误差

热度:836   发布时间:2016-04-17 13:29:46.0
Double.parseDouble("554546") * Double.parseDouble("0.05")=27727.300000000003 ,如何减少误差
Double.parseDouble( "554546 ")   *   Double.parseDouble( "0.05 ")=27727.300000000003  

如何减少误差

------解决方案--------------------
BigDecimal b1 = new BigDecimal( "554546 ");
BigDecimal b2 = b1.multiply(new BigDecimal( "0.05 "));
System.out.println(b2.setScale(15, BigDecimal.ROUND_DOWN));
------解决方案--------------------
DecimalFormat format = new DecimalFormat( "#.00 ");
double num=Double.parseDouble( "554546 ") * Double.parseDouble( "0.05 ")=27727.300000000003;
format.format(num); Ok!
  相关解决方案