首页 > 其他分享 >【BigDecimal】non-terminating decimal expansion; no exact representable decimal result.

【BigDecimal】non-terminating decimal expansion; no exact representable decimal result.

时间:2023-03-11 22:33:44浏览次数:29  
标签:non BigDecimal no decimal terminating result

问题,如题。

意思是,使用 BigDecimal 除法,产生了无限循环小数,产生了bug。

解决方法,很简单
a.divide(b, 2, BigDecimal.ROUND_HALF_UP);

意思就是 a / b, 保留两位小数,然后采用的是4舍5入的方式。
嗯,然后,第三个参数,有很多,点方法进去看一眼就知道了。

标签:non,BigDecimal,no,decimal,terminating,result
From: https://www.cnblogs.com/aaacarrot/p/17207209.html

相关文章