VAT Rounding Error

Created on 22 November 2020, over 3 years ago
Updated 24 December 2020, over 3 years ago

Problem/Motivation

Calculation of VAT is a highly critical thing (at least with my tax office). Passing a wrongly calculated invoice to my accountant, I get back a problem report of wrongly rounded TAX values, and clients ridicule Drupal Commerce.

Steps to reproduce

Calculating a product:
Product Price: 49,08
General Fee: 69,08
(Subtotal: 118,16) (isn't displayed in the checkout)
20% VAT: 23,64 (WRONG - 118,16 * 20% = 23,632, should be 23,63 after rounding)
Total: 141,80 (WRONG - should be 141,79)

Proposed resolution

There are many ways to do it right. Not using floats but (larger) integers and commercial rounding are the best bets.
Using integers would work like this:
4908 + 6908 = 11816
11816 * 0,2 = 2363
11816 + 2363 = 14179
Display with a decimal comma at position "2nd from right".
At least we used to do this back in the stone age of commercial software development.

Using PHP round() should however result in proper rounding -- makes me wonder what's going on here.

πŸ’¬ Support request
Status

Closed: duplicate

Version

2.21

Component

Tax

Created by

πŸ‡¦πŸ‡ΉAustria nofue

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Greenhorn

    Hello,
    I would like to address this problem here again, even though it was a long time ago.
    First of all, I would like to thank you, the developers, because anyone can complain but it is always difficult to provide constructive solutions. I would like to help find solutions, but I don't know where to start right now.

    Nevertheless the problem still exists. If there is already a patch that I haven't considered, please let me know.

    We created a shop with Drupal commerce 8.x-2.38.
    The prices in the shop have all been set to include tax.
    Now we have the problem that when ordering several products, the tax is not calculated correctly.
    We have noticed that the tax is calculated per order item and then added up.
    This is not a problem for smaller orders but for multiple items the tax becomes inaccurate.

    Here is a simple example with a tax of 7%:
    One item costs €4.20 including 7% tax
    So the calculation of the tax is:
    (4.20 / 107) * 7 = 0.2747... rounded = 0.27, is ok

    but for 5 items with the price of 4.20 including tax of 7%
    the correct calculation would be:
    5 x 4.20 = 21.00
    Tax:
    (21.00 / 107) *7 = 1.3738... rounded = 1.37 is ok

    Since you calculate the tax per order item and then add it up, you get the following tax:
    (4.20 / 107) * 7 = 0.2747... rounded = 0.27

    0.27 x 5 = 1.35 and that is not correct in a tax country like Germany ;)

    Is it possible to create a new property that contains the following per order:
    Total tax per tax rate (7%, 19%, .... depending on the settings) only based on the order items and depending on whether tax is included or not.
    These values should also be saved in the order as total tax, if that is possible.

    Thank you very much and we look forward to a constructive exchange

Production build 0.69.0 2024