【異常】java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal

異常緣由:沒有指定數據精度致使數據運算沒法正常結算ide

如執行下面的除法:spa

int value = BigDecimal.valueOf(211111).divide(BigDecimal.valueOf(3)).intValue();

指定精度後就能夠了:code

int value = BigDecimal.valueOf(210000).divide(BigDecimal.valueOf(3), 2, BigDecimal.ROUND_HALF_UP).intValue();
相關文章
相關標籤/搜索