4 / 4
Sep 2022

I set-up a 10% discount code. The product price, before discount, is $194.75. 10% off should yield a $19.48 discount. But it's only calculating $18.45.



This is an "all items" percentage discount. FYI, it's a quantity of 205, per-item price of $.95.

  • created

    Feb '11
  • last reply

    Sep '22
  • 3

    replies

  • 1.2k

    views

  • 3

    users

  • 2

    links

The reason for the discrepancy is explained on this help page:

4http://www.e-junkie.com/ej/trouble.discounts.discrepancy.htm4



Normally, that would result in a discrepancy of maybe a few cents, but the same rounding imprecision applied across 205 items is magnifying the discrepancy in your case. A 10% discount amounting to $19.475 off the order total, spread across 205 items, works out to a discount of $0.095 off the price of each item, but we can't pass individual item prices to checkout with sub-cent precision, so that gets rounded to $0.09 off per item, times 205 items = $18.45 total discount.



If this isn't reflecting an actual or likely order, and you're just testing the discount function, try making a dummy product with whatever price you wish, that you can Add to Cart to test with the discount code.

11 years later

Can this be looked at again? This seems to be more complicated than it needs to be to end up with a wrong number.

It looks like the math is the following:
1. Get the pre-discount cart item total * the percent discount
(so in the original example, it would be $194.75 * .10 = 19.475)
2. Take the result from number 1 and divide it by the quantity to get the discount per item, truncated to two decimal places if the third decimal is 5 or lower, or round to two decimal places if the third decimal is greater than 5
(19.475/205 = .095 truncated to .09)
3. Take the result from #2 and multiply it back by the quantity to get a different answer from #1
(so .09*205) = $18.45

Why are steps 2 and 3 necessary? If it's necessary to calculate the discount per item, is the rounding correct? Why is .095 truncated to .09 and not rounded to .1?

To expand on our help page about this1, PayPal in particular doesn't allow us to pass any whole-order total or discount amounts to checkout; they only allow us to pass individual item prices (and tax/shipping amounts), so we have to distribute any Cart Item Total discount amount across the price(s) of all items in the buyer's cart.

As for why partial-cent decimal remainders get truncated rather than properly rounded, I think that's just a matter of our database fields for prices only being able to handle up to 2 decimal places, so any additional decimal places just get dropped.