Java Utililty Methods BigDecimal Round

List of utility methods to do BigDecimal Round

Description

The list of methods to do BigDecimal Round are organized into topic(s).

Method

BigDecimalround(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) {
    ...
BigDecimalround(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));
doubleround(BigDecimal d, int decimalPlace)
round
d = d.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return d.doubleValue();
longround(BigDecimal decimal)
Rounds the value to a long using java.math.RoundingMode#HALF_UP
return decimal.setScale(0, ROUNDING_MODE).longValue();
BigDecimalround(BigDecimal decimal)
round
return new BigDecimal(Math.round(decimal.doubleValue()));
BigDecimalround(BigDecimal decimal, int decimalDigits)
round
BigDecimal scale = new BigDecimal(Math.pow(10, decimalDigits));
return new BigDecimal(Math.round(decimal.multiply(scale).doubleValue())).divide(scale);
BigDecimalround(BigDecimal decimal, int precision)
Rounds the given decimal to the given precision using the default rounding algorithm.
return round(decimal, precision, null);
BigDecimalround(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);
BigDecimalround(BigDecimal initData, int scale)
round
if (initData == null) {
    return null;
return initData.setScale(scale, BigDecimal.ROUND_HALF_UP);
BigDecimalround(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);