Example:
public class Round {
private static final BigDecimal TWELVE = new BigDecimal("12");
public static void main(String[] args) {
BigDecimal annualAmt = new BigDecimal("55867.59");
BigDecimal monthlyAmt = null;
monthlyAmt = annualAmt.divide(TWELVE, 0, RoundingMode.HALF_UP);
System.out.println(monthlyAmt);
}
}
The above program output is 4656. I want to round this to the nearest hundredth as 4700.
Similarly 4235 --> 4200
To round a given BigDecimal
to the nearest hundred, use monthlyAmt = monthlyAmt.setScale(-2, RoundingMode.HALF_EVEN)
(or substitute the appropriate rounding mode).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With