0

I have this code:

public BigDecimal getDifference() {
    BigDecimal total = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_DOWN);

    for (Order order : orders) {
        BigDecimal originalCost= order.getOriginalValue();

        BigDecimal nweCost= order.getNewValue();

        BigDecimal diff = newValue.substract(originalValue);

        total.add(diff);
    }

    return total;
}

I am testing with originalCost > newCost but total is always 0. I took a snapshot of the debugger at the line total.add(diff):

debugger

Does anybody know what I am doing wrong?

Thanks.

mario595
  • 3,671
  • 7
  • 34
  • 57

1 Answers1

2
total = total.add(diff);

Immutable type, like String.

Some IDEs give a warning.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    Thanks! Sorry for the dup, I though the problem was on the subtract method so I didn't search properly. – mario595 Jul 25 '14 at 11:21