I am using BigDecimal to make some calculations. Recently I ran into:
java.lang.ArithmeticException:
Non-terminating decimal expansion; no exact representable decimal result.
The answer to that problem was posted here: ArithmeticException: "Non-terminating decimal expansion; no exact representable decimal result"
This means, there is some division with unlimited decimals, so BigDecimal tells me it cannot calculate the result exactly. To avoid this I have to call BigDecimal.setScale(SOMETHING, ROUNDING_MODE);
EDIT:
The problem now is to set the SOMETHING to the maximum possible value. I could use a MathContext with precision below UNLIMITED (MathContext(precision)
) but the same problem occurrs there. There would need to be a value below
MathContext.UNLIMITED
...
Does anyone know how to accomplish that?
Moved my second question to: Why is there no BigDecimal.setPrecision() method?
Thank you!
Oliver