BigDecimal amount = ZERO;
if (adj.get("amount") != null) {
// pro-rate the amount
// set decimals = 100 means we don't round this intermediate value, which is very important
amount = adj.getBigDecimal("amount").divide(originalOrderItem.getBigDecimal("quantity"), 100, rounding);
amount = amount.multiply(billingQuantity);
// Tax needs to be rounded differently from other order adjustments
if (adj.getString("orderAdjustmentTypeId").equals("SALES_TAX")) {
amount = amount.setScale(taxDecimals, taxRounding);
} else {
amount = amount.setScale(invoiceTypeDecimals, rounding);