Java Utililty Methods BigDecimal Add

List of utility methods to do BigDecimal Add

Description

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

Method

StringaddBigDecimals(String value1, String value2)
add Big Decimals
BigDecimal result = (new BigDecimal(value1.trim())).add(new BigDecimal(value2.trim()));
return String.valueOf(result);
voidaddBigDecimalsInMap(Map baseMap, Map addMap)
add Big Decimals In Map
if (baseMap == null || addMap == null)
    return;
for (Map.Entry<String, Object> entry : addMap.entrySet()) {
    if (!(entry.getValue() instanceof BigDecimal))
        continue;
    BigDecimal addVal = (BigDecimal) entry.getValue();
    Object baseObj = baseMap.get(entry.getKey());
    if (baseObj == null || !(baseObj instanceof BigDecimal))
...
BigDecimaladdPercent(BigDecimal price, double amount)
add Percent
return price.add(getPercentageValue(price, amount));
BigDecimaladdQtde(BigDecimal val1, BigDecimal val2)
add Qtde
BigDecimal aux = val1;
aux = aux.setScale(decQtde, roundingMode);
return aux.add(val2).setScale(decQtde, roundingMode);
voidaddSalePrice(Map complexSalePrice, BigDecimal saleprice)
add Sale Price
if (!complexSalePrice.containsKey(saleKey)) {
    complexSalePrice.put(saleKey, saleprice);
} else {
    BigDecimal existedPrice = complexSalePrice.get(saleKey);
    BigDecimal priceResult = existedPrice == null ? BigDecimal.ZERO : existedPrice;
    complexSalePrice.put(saleKey, priceResult.add(saleprice));
BigDecimaladdToBigDecimalInMap(Map theMap, K mapKey, BigDecimal addNumber)
Assuming theMap not null; if null will throw a NullPointerException
Object currentNumberObj = theMap.get(mapKey);
BigDecimal currentNumber = null;
if (currentNumberObj == null) {
    currentNumber = ZERO_BD;
} else if (currentNumberObj instanceof BigDecimal) {
    currentNumber = (BigDecimal) currentNumberObj;
} else if (currentNumberObj instanceof Double) {
    currentNumber = new BigDecimal(((Double) currentNumberObj).doubleValue());
...
voidaddToBigDecimalInMap(Object key, BigDecimal value, Map theMap)
add To Big Decimal In Map
if (value == null || theMap == null)
    return;
Object curObj = theMap.get(key);
if (curObj == null) {
    theMap.put(key, value);
} else {
    BigDecimal curVal;
    if (curObj instanceof BigDecimal)
...
BigDecimaladdUlp(BigDecimal x)
add Ulp
BigInteger unscaledValue = x.unscaledValue();
unscaledValue = unscaledValue.add(BigInteger.ONE);
return new BigDecimal(unscaledValue, x.scale());
intaddVAT(int priceInCents, BigDecimal vat)
add VAT
return addVAT(new BigDecimal(priceInCents), vat).intValueExact();
BigDecimaladdVatAmount(BigDecimal percentage, BigDecimal amount)
add Vat Amount
return amount.multiply(percentage.divide(HUNDRED));