java 中 Integer 跟 double类型相乘还有比较的问题
今早遇到了一个问题 Integer 跟 double类型相乘的问题
eg1:
Integer packSize = 2;
Integer qty = 7;
Double nw = 20.4;
int result = qty - qty % packSize;
System.out.println(qty % packSize);
System.out.println(qty - qty % packSize);
System.out.println(nw * result);
输出结果:
6
122.39999999999999
eg2:
Integer packSize = 2;
Integer qty = 7;
Double nw = 20.5;
int result = qty - qty % packSize;
System.out.println(qty % packSize);
System.out.println(qty - qty % packSize);
System.out.println((float
)nw * result);
输出结果:
6
122.4
然后我选者了BigDecimal
eg:
public static void main(String arg[]){
BigD