Java中BigDecimal的一个除法异常

https://www.cnblogs.com/chengyujia/p/7873542.html

 

java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
说明遇到除不尽的情况了,需要指定商的小数精度和舍入模式。
比如:
a=b.divide(c,2,RoundingMode.HALF_UP);

Leave a Reply

Your email address will not be published. Required fields are marked *