Search code examples
javaroundingbigdecimal

Rounding of BigDecimal


I want to do rounding of Bigdecimal e.g my 0.1 then it should round as 1. I tried with Round_UP, all Rounding Function Please help me out


Solution

  • I suppose you used the round method. Instead, you should change the scale to 0.

    BigDecimal bd = BigDecimal.valueOf(0.1);
    BigDecimal rounded = bd.setScale(0, RoundingMode.UP); // 1