What causes “Non-terminating decimal expansion” exception from BigDecimal.divide? [duplicate]

Non-terminating decimal need rounding

When using divide you should use a MathContext with RoundingMode in case the exact result has an infinite number of decimals.

Such is your case:

MathContext mc = new MathContext(2, RoundingMode.HALF_UP) ;
BigDecimal bd3 = bd1.divide(bd2, mc);

Alternatively call divide with a rounding mode to use the scale of the numerator (bd1 in the example below):

BigDecimal bd3 = bd1.divide(bd2, RoundingMode.HALF_UP);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)