List of utility methods to do BigDecimal Round
BigDecimal | round(BigDecimal b, int precision) round a number to an arbitrary precision based on http://www.crazysquirrel.com/computing/java/basics/rounding.jspx * BigDecimal(d); * b.scale() + precision ), RoundingMode.HALF_UP); * b.round(context).doubleValue(); double exp=Math.pow(10, precision); * d*=exp; long dlong=Math.round(d); * * return dlong/exp; } */ public static BigDecimal round(BigDecimal b, int precision) { ... |
BigDecimal | round(BigDecimal d, int decimalDigits, RoundingMode rmode) Round the passed BigDecimal so that only decimalDigits remain after the point.
return d.round(new MathContext(intDigits(d) + decimalDigits, rmode)); |
double | round(BigDecimal d, int decimalPlace) round d = d.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return d.doubleValue();
|
long | round(BigDecimal decimal) Rounds the value to a long using java.math.RoundingMode#HALF_UP return decimal.setScale(0, ROUNDING_MODE).longValue();
|
BigDecimal | round(BigDecimal decimal) round return new BigDecimal(Math.round(decimal.doubleValue())); |
BigDecimal | round(BigDecimal decimal, int decimalDigits) round BigDecimal scale = new BigDecimal(Math.pow(10, decimalDigits)); return new BigDecimal(Math.round(decimal.multiply(scale).doubleValue())).divide(scale); |
BigDecimal | round(BigDecimal decimal, int precision) Rounds the given decimal to the given precision using the default rounding algorithm. return round(decimal, precision, null);
|
BigDecimal | round(BigDecimal dividend, int divisor) round if (dividend == null || divisor == 0) { return dividend; BigDecimal remainder = dividend.remainder(BigDecimal.valueOf(divisor)); return remainder.equals(BigDecimal.ZERO) ? dividend : remainder.intValue() < divisor / 2 ? floor(dividend, divisor) : ceiling(dividend, divisor); |
BigDecimal | round(BigDecimal initData, int scale) round if (initData == null) { return null; return initData.setScale(scale, BigDecimal.ROUND_HALF_UP); |
BigDecimal | round(BigDecimal money, int scale) round if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); BigDecimal one = new BigDecimal("1"); return money.divide(one, scale, BigDecimal.ROUND_HALF_UP); |