Double BigDecimal 精度丢失总结
Double 加减乘除会存在精度丢失问题,这个不用多说,建议BigDecimal
现在说说用了BigDecimal 精度还是丢失,这样有点妖
验证后总结 new BigDecimal 直接用 Double.parseDouble 精度还是会丢失,这里备记一下
BigDecimal 正确用法
方式一 :
BigDecimal decJEY1 = BigDecimal.valueOf(Double.parseDouble("1193.75"));
方式二:
BigDecimal decJEY1 = new BigDecimal(Double.toString(Double.parseDouble("1193.75")));
BigDecimal 错误用法 精度丢失
BigDecimal decJEY1 = new BigDecimal(Double.parseDouble("1193.75"));
列子如下图: