日期:2014-05-18  浏览次数:20767 次

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!