当前位置: 代码迷 >> 综合 >> Non-terminating decimal expansion
  详细解决方案

Non-terminating decimal expansion

热度:17   发布时间:2024-01-12 05:11:24.0

BigDecimal除法运算报错,错误如下:
Non-terminating decimal expansion; no exact representable decimal result

 

原因是:

BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)

if divisor is zero, roundingMode==ROUND_UNNECESSARY and the specified scale is insufficient to represent the result of the division exactly
所以应该指定scale和roundingMode,保证对于无限小数有足够的范围来表示结果。