Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding Error in Total Price Calculation #1204

Open
jochemschulten opened this issue Feb 5, 2025 · 0 comments
Open

Rounding Error in Total Price Calculation #1204

jochemschulten opened this issue Feb 5, 2025 · 0 comments

Comments

@jochemschulten
Copy link

The issue arises from rounding during the calculation of the exclusive price in the cleanExclusive function of the InclusiveAccuracyFix trait.

Example:

  • Product price: 15.00€ (Including 21% VAT)
  • Quantity: 12
  • The total is shown as: € 180.05, but it should be € 180.04.

Explanation:

The rounding happens when the exclusive price is calculated in the cleanExclusive function. Here's the problem:

  1. The product price of € 15.00 (including 21% VAT) is divided by 1 + ($factor / 100) to get the price excluding VAT:

    • In the case of 21% VAT, the calculation is € 15.00 / 1.21 = € 12.3966942.
  2. However, the result is rounded using RoundingMode::HALF_UP, which causes the price to be rounded to 12.40€ instead of 12.3966942€. The rounding cannot be disabled due to restrictions of brick/math.

  3. The final calculation is:

    • € 12.40 * 12 = € 148.80.
    • Adding the VAT: € 148.80 * 1.21 = € 180.04800, which rounds up to € 180.05 instead of € 180.00.

This rounding leads to an incorrect total price.

Steps to reproduce:

  1. Add a product priced at € 15.00 (including 21% VAT) to the cart.
  2. Set the quantity to 12.
  3. Observe the total price being calculated as € 180.05 due to the rounding in the cleanExclusive function.

Expected behavior: The rounding should be avoided in the cleanExclusive function or handled differently so the exclusive price is not rounded prematurely. The total should be € 180.00 instead of € 180.05.
The product price of € 15.00 (including 21% VAT) is divided by 1 + ($factor / 100) to get the price excluding VAT: € 12.3966942. Price excluding VAT multiplied by product quantity 12 = € 148.76033 + VAT = € 179.999999 which will be rounded to € 180 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant