Rounding issue in Discount Calculation of Order Edit

Solved
sillycube
Shopify Partner
693 16 101

I am trying to apply a discount with Order Edit but find that there is a rounding error. 

Firstly, I try to use Shopify Discount Calculator to apply 15% off discount on a $4.25 product, it's showing $3.61:

discount-calculator.png

When I try to Add discounts to items while editing orders (The new feature released in Oct 2020), the discounted price is showing $3.62:

order-edit.png

 When I test with my calculator, it's showing $3.6125:

calculator.png

I think there is a rounding issue in your order edit API. I don't understand why $3.6125 is rounding to $3.62. The first item $2.5 * 0.85 = $2.125 and it's rounding to $2.13 

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
Accepted Solution (1)

Accepted Solutions
syf_
Shopify Staff
Shopify Staff
95 20 19

This is an accepted solution.

Hi @sillycube,

What you're seeing is expected behaviour due to how Shopify's system uses and calculates discounts, and not necessarily because of order editing. I believe you commented on this forum post where this comment elicits this. Actual discounts are rounded down to 2 d.p. Hence the reason you see 3.62 instead of 3.61 which you expect.

Using the example provided you provided, 15% off 4.25 is 0.6375, which when rounded down to 2 d.p. becomes 0.634.25 - 0.63 = 3.62

Hope this clears things up for you. If there are reasons why how we calculate discounts affect your business, please do share, and I'll make sure to pass that along to the appropriate team.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 4 (4)
syf_
Shopify Staff
Shopify Staff
95 20 19

This is an accepted solution.

Hi @sillycube,

What you're seeing is expected behaviour due to how Shopify's system uses and calculates discounts, and not necessarily because of order editing. I believe you commented on this forum post where this comment elicits this. Actual discounts are rounded down to 2 d.p. Hence the reason you see 3.62 instead of 3.61 which you expect.

Using the example provided you provided, 15% off 4.25 is 0.6375, which when rounded down to 2 d.p. becomes 0.634.25 - 0.63 = 3.62

Hope this clears things up for you. If there are reasons why how we calculate discounts affect your business, please do share, and I'll make sure to pass that along to the appropriate team.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

MAP2
New Member
2 0 7

I just noticed the same problem with my 10% member discount.  The item was priced at $6.98, so the discount should be .70, not .69 like Shopify calculated.  Interesting enough, it had .70 at first and then changed it to .69!  I suggest you folks read up on basic math principles for rounding.

You NEVER automatically round down to 2 dp.  The value of the 3 dp tells you whether you are rounding up or down as indicated here; Simple Rules for Rounding Numbers Correctly (thoughtco.com)  I hope Shopify will fix this ASAP.

Our members deserve their full discount.  They don't deserve to have Shopify cheat them out of that, even if it's just a penny!

caricky
New Member
2 0 3

It affects every business that uses discounts on Shopify massively.

If your advertising to customers they are getting 25% off, that's the minimum they should get, any amount under could be described as mis-selling.

Example:

I have buy 2 or more for 25% off whole order.

Product 1 is £4.50
Product 2 is £4.25

The exact calculation is £2.1875 discount, £6.5625 to be paid.

Shopify says the discount is £2.18 discount,  £6.57 to be paid.

It's backwards, the rounding should be benefiting the customer, not the merchant.

The customer is only getting 24.91428571428571% discount, not 25%

Thanks,

Craig

inkstore2
New Member
1 0 0

Hi all,  just encountered the same kind of issue when importing markdown sales from eBay in to my Shopify store (Supply theme ).  Item prices are all correct - as entered into Bulk Editor, however some of the percent discounts displayed are incorrect, (by 1%)  due to incorrect rounding ... perhaps a minor thing, but very frustrating !

I am displaying the percentage saved on a sale price, (involves a slight tweak to the price-sale.liquid snippet). The actual discounted prices are all correct, however Shopify will round DOWN all percentages to display the next lower integer .  Since there is a small degree of normal rounding in all calculations, when re-quoting actual sale prices a 15% discount might translate to 14.97% or 15.03% .  But Shopify will display a calculated 14.97%  as "SAVE 14% (incorrect), and 15.03%  as  "SAVE 15%  (correct).  This gives a messy and inconsistent look to my collection pages.

Simply truncating or cutting off the decimal places is not the usual definition of rounding.  In addition using the math filter "round" didn't fix the problem either,  so I figured that the auto rounding function must be built in to some other file.  I searched the forum pages for any help on this, but couldn't find much. So, although a newbie to Liquid, I set about figuring out a work-around, for where Shopify was dropping the displayed discount by 1%  (5% was showing as 4%, 15% as 14%  etc, ) .

I came up with the following  if / elsif matrix, which is fairly straight forward and works for me, and something similar might work for anyone finding a similar issue, 

 

{% assign discount_percent = compare_price | minus: product_price | times: 100 | divided_by: compare_price %}

{% if discount_percent >= 4 and discount_percent < 5 %}
{% assign result = discount_percent %}
 {{ result | plus: 1 }}%

{% elsif discount_percent >= 5 and discount_percent < 14 %}
{% assign result = discount_percent %}
 {{ result | plus: 0 }}%

{% elsif discount_percent >= 14 and discount_percent < 15 %}
{% assign result = discount_percent %}
 {{ result | plus: 1 }}%

{% elsif discount_percent >= 15 and discount_percent < 24 %}
{% assign result = discount_percent %}
 {{ result | plus: 0 }}%

{% elsif discount_percent >= 24 and discount_percent < 25 %}
{% assign result = discount_percent %}
 {{ result | plus: 1 }}%

{% elsif discount_percent >= 25 %}
{% assign result = discount_percent %}
 {{ result | plus: 0 }}%

{% endif %}