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);