Answer the question
In order to leave comments, you need to log in
Working with BigDecimal, how to discard the fractional part?
I need to calculate A * B / 100
BigDecimal result = null;
BigDecimal a = new BigDecimal(this.getA());
a.setScale(2, RoundingMode.UP);
BigDecimal b = new BigDecimal(this.getB());
b.setScale(2, RoundingMode.UP);
result = a.multiply(b).divide(new BigDecimal(100), RoundingMode.UP);
result.setScale(0, RoundingMode.UP);
if (result != null) {
System.out.println (result.toString());
}
Answer the question
In order to leave comments, you need to log in
setScale() returns a new BigDecimal instance. And you ignore him.result = result.setScale(0, RoundingMode.UP);
BigDecimal a = BigDecimal("15");
BigDecimal b = BigDecimal("2");
BigInteger c = a.divide(b).toBigInteger();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question