我的代码是::
public Boolean calculation(){
Double totalQuantitySum = 0d,totalAmountSum=0d;
Boolean balanced=false;
for(MaterialAcceptingRejectSheetCustomizationBean bean: materialAcceptingRejectSheetBean.materialAcceptingRejectSheetCustomizationBeanList){
if(bean.totalAmount != null && bean.totalQuantity!= null){
totalQuantitySum += bean.totalQuantity;
totalAmountSum += bean.totalAmount;
System.out.println(totalQuantitySum+" "+totalAmountSum);
}
if(totalQuantitySum.equals(materialAcceptingRejectSheetBean.totalQty) && totalAmountSum.equals(materialAcceptingRejectSheetBean.totalAmount)){
balanced= true;
}
}
System.out.println(balanced);
return balanced;
}
为什么这个函数总是返回false ???
答案 0 :(得分:0)
我只是瞥了一眼,但我怀疑问题可能是你要比较双倍。处理浮点数时,由于小数位数会产生错误。