Dawn - Discount Percentage price calculation at cart is randomly off in mutiple products by 1 cent

[Dawn 11.0.0]

I’m applying a 25% discount to every product with a discount code. But I wanted to show that discount benefit on the product page, so I’m editing price.liquid in order to show the new price (I’m not applying the discount right there, I’m just showing it)

That’s when I noticed, that the price is slightly different in the cart.

So, for instance, the new price of my product Trillium should be 7 * 0.75 == 5.25 , right?
(25% discount, 100% -25% = 75%, multiply it by the price and you get the new price)

But in the cart, where the discount is effectively applied, I see the new price as 5.26 €

herastore_1-1699297890338.png

So, why is the discount code failing to do simple math?

Initially I thought it was just rounding prices with a Floor function (ex: 5.256 turns into 5.25) but I have multiple examples where it behaves a bit randomly, sometimes it rounds up, sometimes it rounds down, and in my product Trillium it rounds up, even though the price did not need to be rounded at all.

It’s not good for us as a store to show different prices in different pages, but I can’t seem to find out why this happens, can anyone help or point me in the right directions?

2 Likes

Hey @herastore

Shopify uses specific rounding rules for pricing. These rules aim to ensure consistency and fairness in pricing calculations. It’s possible that the 1 cent difference is due to these rounding rules. Unfortunately, you cannot disable these rules, but you can adjust your displayed prices slightly to minimize the impact.

Thanks

1 Like

Thanks!
Those rules are weird.. Is there any place where I can see those rules in order to mimic them? Otherwise it’s impossible for me to show the same prices as them

@azamgill Even using Shopify’s own discount calculator (which I just found), for the same case I presented, says it’s 5.25 :sad_but_relieved_face:

1 Like

We were having the same issue. In our case we notice that the price is always rounded up. So if you have a discount of 10% on a product with a price 3.99 it gives 3.591 which in the checkout is rounded to 3.60. This happens consistenly around precentage discounted price which have a 0.001 or more. @herastore Does the prices vary for you, ist there a point where shopify rounds the price down when using percentage discounts? Im currently following this up with Shopify Support to see if we can get a defenitive answer. Ill include my findings on this as soon as I get a response.

Hey!

It’s been a while since I had this issue.. which I could not solve btw, no one on Support could help.

I don’t have the same real examples now because I gave up, but I remember very well I had examples for both cases: when it randomly would round up, while on other cases it would round down, som random stuff just like the example I showed in this ticket.

Because if it would round always up, for istance, it would be easy to replicate, even if it seemed wrong. But there was no pattern or formula as far as I could investigate

Yeah if you have news on this please reach out, I would appreciate it!