java中double数据失精度(失真)问题处理
直接上代码:
public static void main(String[] args) { double db1 = 87406.70; double db2 = 778.93; double result = db1 + db2; System.out.println(result); BigDecimal b = new BigDecimal(result); result = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); System.out.println(result); }