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

BigDecimaladjustCurrencyDecimalPoint(final BigDecimal value, final int decimal)
Adjusts the BigDecimal from JCo value to the correct customized one.
final long withoutDecimalPoint = value.unscaledValue().longValue();
final BigDecimal newValue = BigDecimal.valueOf(withoutDecimalPoint, decimal);
return newValue;
booleanareEqual(BigDecimal aThis, BigDecimal aThat)
are Equal
return aThis.setScale(2).equals(aThat.setScale(2));
booleanareEqual(BigDecimal first, BigDecimal second)
are Equal
BigDecimal rightBoundary = second.add(new BigDecimal(IMPRESSION));
BigDecimal leftBoundary = second.subtract(new BigDecimal(IMPRESSION));
return first.compareTo(rightBoundary) <= 0 && first.compareTo(leftBoundary) >= 0;
BigDecimal[]asArray(final BigDecimal... elements)
as Array
return elements;
BigDecimalaverage(BigDecimal... values)
average
double sum = 0;
for (BigDecimal val : values) {
    sum += val.doubleValue();
return new BigDecimal(sum / values.length);
BigDecimalaverage(final BigDecimal... numbers)
average
return IntStream.range(0, numbers.length).mapToObj(i -> numbers[i]).reduce((sum, next) -> sum.add(next))
        .map(sum -> sum.divide(BigDecimal.valueOf(numbers.length))).orElse(BigDecimal.ZERO);
double[]bigDecimalListToArray(List list)
big Decimal List To Array
double[] array = new double[list.size()];
for (int i = 0; i < list.size(); i++) {
    array[i] = list.get(i).doubleValue();
return array;
BigDecimalbigDecimalObjectValue(Object input)
Convert an object to a byte, allow nulls
if (input instanceof BigDecimal) {
    return (BigDecimal) input;
if (isBlank(input)) {
    return null;
return BigDecimal.valueOf(doubleValue(input));
BigDecimalbigDecimalParse(String value)
big Decimal Parse
return new BigDecimal(value);
StringbigDecimalPrint(BigDecimal value)
big Decimal Print
final int scale = 2;
String bigDecString = null;
StringBuffer sB = null;
String dV = null;
StringBuffer str = null;
bigDecString = value.toString();
sB = new StringBuffer(bigDecString);
boolean isDecimalPointFound = false;
...