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

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