BigDecimal相加总是为0
public BigDecimal getTotalPrice() {
BigDecimal totalPrice = new BigDecimal(0);
for (Map.Entry<Integer, CarItem> entry : items.entrySet()) {
totalPrice.add(entry.getValue().getPrice());
}
return totalPrice;
}
正确写法:
public BigDecimal getTotalPrice() {
BigDecimal totalPrice = new BigDecimal(0);
for (Map.Entry<Integer, CarItem> entry : items.entrySet()) {
totalPrice = totalPrice.add(entry.getValue().getPrice());
}
return totalPrice;
}