原文地址 http://www.cnblogs.com/Dtscal/p/3485405.html
常用方法:
<span style="font-size:18px;">float price=89.89;
int itemNum=3;
float totalPrice=price*itemNum;
float num=(float)(Math.round(totalPrice*100)/100);//如果要求精确4位就*10000然后/10000</span>
本文介绍了一种在Java中进行精确浮点数运算的方法,通过将浮点数转换为整数进行计算后再转回浮点数的方式,避免了直接使用浮点数计算可能带来的精度误差问题。
原文地址 http://www.cnblogs.com/Dtscal/p/3485405.html
常用方法:
<span style="font-size:18px;">float price=89.89;
int itemNum=3;
float totalPrice=price*itemNum;
float num=(float)(Math.round(totalPrice*100)/100);//如果要求精确4位就*10000然后/10000</span>
1万+

被折叠的 条评论
为什么被折叠?