代码如下:
//计算总金额
it = null;
Double countfree=0.0;
it = list2.iterator();
while (it.hasNext()) {
Object[] obj = (Object[]) it.next();
obj[31] = obj[31]==null ? 0.0 : obj[31];
countfree += Double.valueOf(obj[31].toString());
}
DecimalFormat df = new DecimalFormat("0.00");
String num = df.format(countfree);
将list2中一个数值字段进行累加,有个别会出现 1.083306722E7 这样的值,为什么会这样? 怎么处理?
如果有更好的累加方法也望分享下
------解决方案--------------------
不要用double进行计算用BigDecimal的add来进行+法运算