Rounding Percentage Discounts

When calculating percentage discounts, the digits are rounded based on the currency precision. This can lead to slight differences on the total price.

Rounding Percentage Discount on Products

The discounts defined on product level are calculated for a single unit. The resulting discount value goes through 2 steps of rounding:

  1. Round down the value if its digit number is higher than the value of DECLARATIVE_UNROUNDED_PRECISION.
  2. Round the value according to the currency digits, using final AbstractAmount discountAmount = new Money(adjustedDiscountAmount, currency). For USD the default digits precision is 2, so a value of 0.234$ rounds to 0.23$.

If there are multiple product discounts, each time the base price is updated by subtracting the discount value before the next calculation. To avoid the loss of an ignorable number of cents, you can change the price units, such as maintaining the price per 100 units.

After the calculation of the discount per unit, the outcome is multiplied with the quantity of the product.

Rounding Percentage Discount on Cart

The discounts defined on cart level promotions are calculated for the total amount of the order units. The resulting value goes through 2 steps of rounding:

  1. Round down the value if its digit number is higher than the value of DECLARATIVE_UNROUNDED_PRECISION.
  2. Round the value according to the currency digits, using final AbstractAmount discountAmount = new Money(adjustedDiscountAmount, currency).

In there are multiple cart discounts, each time the base price is updated by subtracting the discount value before the next calculation.

Example

Assume that you have a product with a unit price of 1.95$ and a quantity of 1000 on your storefront. You have the following rules defined to be applied:
  1. 12% discount on the product price defined on the DiscountRow
  2. Promotion rule on the product with 13.5% discount
  3. Promotion rule on cart total with 14.6% discount
  4. Promotion rule on cart total with 8.38% discount

If there are multiple discounts, first the product level discounts then the cart level discounts are applied. Discounts defined on the DiscountRow have priority on calculation. The calculation flow for this example is displayed in the figure:

After the first discount, there’s the new discounted price 1.72$ which is used as base price for the next calculation and the appliedDiscountValue of 234$. Similarly the second product level discount also calculates a new discounted price 1.49$, which equals to 1490$ for the quantity of 1000 items. With the appliedDiscountValue of this second discount, the total product level discount value equals to 464$. Adding the cart level discount total to the product level discount, 324.17 + 464, the total discount equals to 788.17$.