Double类型数值相加导致精度缺失问题
问题描述
double v1 = 13.01;
for (int i = 0; i < 10; i++){
v1 += 13;
System.out.println(v1);
}
解决方案
double v1 = 4.5;
double v2 = 4.55;
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
double sum= b1.add(b2).doubleValue();