Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:Main.java

public static void addBigDecimalsInMap(Map<String, Object> baseMap, Map<String, Object> addMap) {
    if (baseMap == null || addMap == null)
        return;//from   w w  w. j  ava 2 s  .  c  om
    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))
            baseObj = BigDecimal.ZERO;
        BigDecimal baseVal = (BigDecimal) baseObj;
        baseMap.put(entry.getKey(), baseVal.add(addVal));
    }
}

From source file:be.error.rpi.ebus.Support.java

public static String addTemperatureToCommand(String command, BigDecimal temperature, int offset) {
    String converted = encodeDATA2c(temperature.add(new BigDecimal(offset)));
    return format(command, substring(converted, 2, 4), substring(converted, 0, 2));
}

From source file:Main.java

public static BigDecimal sum(final List<BigDecimal> list) {
    BigDecimal total = BigDecimal.ZERO;
    for (final BigDecimal item : list) {
        total = total.add(item);
    }/*from  ww w.  ja v  a 2s.  c  om*/
    return total;
}

From source file:Main.java

public static double addDouble(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.add(b2).doubleValue();
}

From source file:Main.java

public static double add(double value1, double value2) {
    BigDecimal b1 = new BigDecimal(value1);
    BigDecimal b2 = new BigDecimal(value2);
    return b1.add(b2).doubleValue();
}

From source file:Main.java

public static double add(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.add(b2).doubleValue();
}

From source file:Main.java

public static Double add(Double v1, Double v2) {
    BigDecimal b1 = new BigDecimal(v1.toString());
    BigDecimal b2 = new BigDecimal(v2.toString());
    return Double.valueOf(b1.add(b2).doubleValue());
}

From source file:Main.java

public static BigDecimal subtractVatAmount(BigDecimal percentage, BigDecimal amount) {
    BigDecimal f = BigDecimal.ONE
            .subtract(BigDecimal.ONE.divide(percentage.add(HUNDRED).divide(HUNDRED), 14, RoundingMode.HALF_UP));
    return amount.multiply(f).setScale(2, RoundingMode.HALF_UP);
}

From source file:Main.java

public static BigDecimal cosine(BigDecimal x) {

    BigDecimal currentValue = BigDecimal.ONE;
    BigDecimal lastVal = currentValue.add(BigDecimal.ONE);
    BigDecimal xSquared = x.multiply(x);
    BigDecimal numerator = BigDecimal.ONE;
    BigDecimal denominator = BigDecimal.ONE;
    int i = 0;/* w ww.  j  av a2  s  . c o m*/

    while (lastVal.compareTo(currentValue) != 0) {
        lastVal = currentValue;

        int z = 2 * i + 2;

        denominator = denominator.multiply(BigDecimal.valueOf(z));
        denominator = denominator.multiply(BigDecimal.valueOf(z - 1));
        numerator = numerator.multiply(xSquared);

        BigDecimal term = numerator.divide(denominator, SCALE + 5, ROUNDING_MODE);

        if (i % 2 == 0) {
            currentValue = currentValue.subtract(term);
        } else {
            currentValue = currentValue.add(term);
        }
        i++;
    }

    return currentValue;
}

From source file:Main.java

public static double add(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.add(b2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
}