现在的位置: 首页 > 综合 > 正文

Java Exception: Non-terminating decimal expansion

2018年03月23日 ⁄ 综合 ⁄ 共 322字 ⁄ 字号 评论关闭

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,保证对于无限小数有足够的范围来表示结果。

抱歉!评论已关闭.