FROM CACHE - en_header

GraphQL Basics and Troubleshooting

A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Shopify Community
- :
- Partners and Developers
- :
- GraphQL Basics and Troubleshooting
- :
- Re: Rounding issue in Discount Calculation of Order Edit

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Solved

Rounding issue in Discount Calculation of Order Edit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

03-15-2021
01:09 AM

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:

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:

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

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

Solved! Go to the solution

Accepted Solution (1)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

04-07-2021
01:15 PM

This is an accepted solution.

Hi @jam_chan,

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.63`

. `4.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

Replies 8 (8)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

04-07-2021
01:15 PM

This is an accepted solution.

Hi @jam_chan,

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.63`

. `4.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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-19-2021
04:01 PM

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

10-24-2021
01:15 AM

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 %}
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

11-22-2022
11:29 AM

I came across this thread looking for a solution to an incorrect percentage off being displayed on the site. Figured I'd post the solution I ended up using.

```
{%- assign price_save = compare_at_price | minus: price -%}
{%- assign price_save_money = price_save | money -%}
{%- assign price_save_percent = price | times: 1.0 | times: 100 | divided_by: compare_at_price | minus: 100 | round | abs -%}
```

The trick was to remove the rounding from Shopify and take care of it myself. The part that does this is **times: 1.0**. Then at the end I **round** and then take the **abs**olute value (drops all decimal places off)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

09-22-2021
11:23 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

07-06-2022
08:58 AM

Hi @syf_ , this way of rounding is affecting my business too, I agree with all the other users.

In your example discount is 0.64 as you have a 7 in the 3 d.p. (below 5 and above 5 is the discriminant). Besides the issue with giving the customer less discount, this also affect my accounting as when we insert order in our system that calculates the discount correctly, there is alwas a 1p difference for each item sold. It is very annoying and requires accounting procedures to fix the discrepancy, even if it is just 1p

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

11-06-2023
07:12 PM

I also have the same problem...

Sorry? How is this part true?

"0.6375, which when rounded down to 2 d.p. becomes 0.63"

I don't really understand the logic behind it.. Can you provide math proof?

Even using your own liquid's Round method, it gives me 0.64

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-06-2023
06:25 PM

I see what you are saying but this is still incorrect. 15% off of $4.25 is 0.6375. Because the 7 is f and above (basic math) your amount off should be 0.64. This is a constant issue on Shopify which means as orders are moved into our offline operating systems they are constantly having to be adjusted.