Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข4y agoโ€ข
3 replies
Aze

need help with BigDecimal rounding

Hey, I'm trying to round a BigDecimal, but it doesn't seem to be working? I'm not sure if I'm doing it wrong or not.

BigDecimal sum = new BigDecimal("4.36");
BigDecimal coin = new BigDecimal("2.00");
BigDecimal amount = sum.divide(coin, RoundingMode.DOWN);
System.out.println(amount);

judging by the docs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/math/RoundingMode.html#DOWN I was expecting the amount to be
2
, but instead it's
2.18
Was this page helpful?