Relative discount function result can't be reproduced because of strange rounding.

Topic summary

• Issue: Relative percentage discounts calculated by Shopify’s discount function don’t match manual calculations done in Liquid (Shopify’s templating language), causing 1-cent discrepancies.

• Evidence cited: Example from a GitHub issue—$23 with a 2.1739130434782608% discount is expected to be $22.50, but the cart shows $22.51; with quantity 2, total is $45.01, implying the percentage may be rounded to two decimals.

• Reproduction by author: Original price 79.98 with 4% discount. Liquid calculation (rounded to two decimals) produces 76.78, while the discount function returns 76.79.

• Impact: Customers see different prices on product pages versus in the cart/checkout, which is unacceptable for pricing transparency.

• Key gap: No documentation clarifies the function’s rounding behavior (precision, stage of rounding, per-line vs per-unit), preventing consistent replication.

• Status: Unresolved; the author requests official guidance on rounding rules to align displayed and charged prices.

Summarized with AI on December 31. AI used: gpt-5.

In addition to a discount applied to a product at the time of paying, it is common
to show the discounted price in the product page. There are inconsistencies between

the price I get manually calculating a relative discount and applying the function.

This means that customers see a different price when buying and at checkout.

I quote the example provided in an existing issue in Github

Line item price is $23> Percentage discount is 2.1739130434782608> Expected price after discount is $22.50> Actual output in the cart shows $22.51> > With quantity of 2 the total price shows $45.01 which leads me to think that the percentage discount is being rounded to 2 decimal places.> > - See https://github.com/Shopify/function-examples/issues/371

I have experienced a similar case:

Original price: 79,98
Discount 4%

Calculating the discount in liquid is as follows
{% assign price = 79.98 %}
{% assign discount = 4 %}
{% assign proportion = 100 | minus: discount | divided_by: 100%}
{% assign discounted = price | times: proportion %}
{{ discounted | round: 2 }}
// Outputs 76.78

Applying the discount function yields: 76,79

This decimal difference is not acceptable, but there is no information regarding how rounding is

done at the function so that the result can be replicated.

3 Likes