Use of java.math.MathContext

For rounding just the fractional part of a BigDecimal, check out the BigDecimal.setScale(int newScale, int roundingMode) method.

E.g. to change a number with three digits after the decimal point to one with two digits, and rounding up:

BigDecimal original = new BigDecimal("1.235");
BigDecimal scaled = original.setScale(2, BigDecimal.ROUND_HALF_UP);

The result of this is a BigDecimal with the value 1.24 (because of the rounding up rule)

Leave a Comment

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