进行比较因为浮点数在计算机中不准确
所以判定==时会出错
解决方式
double preErrorKey=1e-6; //1*10的-6次方即0.000001 double key1=0.0000001d; double key2=0d; // System.out.println(key1==key2); //结果是flase // System.out.println(Math.abs(key1-key2)<preErrorKey); if(Math.abs(daohuoshuliang- shengoushuliang)<preErrorKey && (weidaohuoliang==0)){ caigouzhuangtai = "全部采购";
原文地址:https://www.cnblogs.com/ukzq/p/12105323.html
时间: 2024-10-04 08:34:47