Round up BigDecimal to Integer value

setScale returns a new BigDecimal with the result, it doesn’t change the instance you call it on. So assign the return value back to value:

value = value.setScale(0, RoundingMode.UP);

Live Example

I also changed it to RoundingMode.UP because you said you always wanted to round up. But depending on your needs, you might want RoundingMode.CEILING instead; it depends on what you want -451.2 to become (-452 [UP] or -451 [CEILING]). See RoundingMode for more.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)