I think I have found a bug:
MathContext mathContext = new MathContext(5, RoundingMode.HALF_UP);
result = BigDecimal.valueOf(0.004798).round(mathContext); // fails
// result is 0.004798!!! (same value)
I had to use the following alternative:
BigDecimal bigDecimal = BigDecimal.valueOf(0.004798);
BigDecimal new_divisor = BigDecimal.valueOf(1, 5);
bigDecimal_array = bigDecimal.divideAndRemainder(new_divisor);
MathContext mathContext = new MathContext(5, RoundingMode.HALF_UP);
result = bigDecimal.subtract(bigDecimal_array[1], mathContext);
result = result.stripTrailingZeros();
This bug (if it is so) is very dangerous in my opinion.