ArithmeticException thrown during BigDecimal.divide

后端 未结 9 672
渐次进展
渐次进展 2020-11-30 08:41

I thought java.math.BigDecimal is supposed to be The Answer™ to the need of performing infinite precision arithmetic with decimal numbers.

Consider the followi

9条回答
  •  执念已碎
    2020-11-30 09:15

    To divide save, you have to set the MATHcontext,

    BigDecimal bd = new BigDecimal(12.12, MathContext.DECIMAL32).divide(new BigDecimal(2)).setScale(2, RoundingMode.HALF_UP);

提交回复
热议问题