I use BigDecimal to do the calculations. As a result of the calculation, I do:
result.setScale(4, RoundingMode.HALF_UP);
Using the .divide BigDecimal method requires scale and rounding, so now I do it like this:
BigDecimal result = bigDecimal1.divide(bigDecimal2, 10, RoundingMode.HALF_UP);
Therefore, I just use a scale large enough to make sure that the calculations are correct. But I'm not sure if this is the right way to do calculations using BigDecimal, and I doubt it ...
Therefore, any pointers are evaluated.
source share