Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

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

Method

StringjoinBigDecimals(List list)
join Big Decimals
String joined = "";
if (list == null) {
    return joined;
for (BigDecimal item : list) {
    joined += item + " ";
return joined.trim();
...
BigDecimaljsonNumberToBigDecimal(final JsonNumber n, final int defaultValue)
json Number To Big Decimal
if (n == null)
    return new BigDecimal(defaultValue);
return n.bigDecimalValue();
BigDecimallimitScale(BigDecimal value, int scale)
limit Scale
if (value.scale() > scale) {
    value = value.setScale(scale, RoundingMode.HALF_UP);
return value;
voidmatchScale(BigDecimal[] val)
Helper to set the scale of two BigDecimal objects to be the same and equal to the higher of the two.
if (val[0].scale() < val[1].scale())
    val[0] = val[0].setScale(val[1].scale());
else if (val[1].scale() < val[0].scale())
    val[1] = val[1].setScale(val[0].scale());
BigDecimalmean(List numbers, MathContext context)
Returns the mean number in the numbers list.
BigDecimal sum = sum(numbers);
return sum.divide(new BigDecimal(numbers.size()), context);
BigDecimalmedian(final BigDecimal[] bigDecimalNumbers)
median
return median(bigDecimalNumbers, 0, bigDecimalNumbers.length);
StringmilliToCent(BigDecimal val)
milli To Cent
return val.divide(BigDecimal.TEN, 0, BigDecimal.ROUND_HALF_UP).toPlainString();
StringmilliToDollar(BigDecimal val)
milli To Dollar
return milliToDollar(val, 0);
longmod(long res, BigDecimal value)
mod
if (value.equals(BigDecimal.ONE)) {
    return res;
} else {
    return res % value.longValue();
BigDecimalmovePoint(final BigDecimal v1, final int shift)
Safe shift (check for null), shift RIGHT if shift>0.
return v1 == null ? null : v1.movePointRight(shift);