Bug 383239 - Automatic VAT split causes offset due to rounding error
Summary: Automatic VAT split causes offset due to rounding error
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.7.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-07 15:50 UTC by Thomas Baumgart
Modified: 2019-08-29 00:51 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.8.1,5.0.0
Sentry Crash Report:


Attachments
Split editor showing offset of one cent (84.40 KB, image/png)
2017-08-07 15:50 UTC, Thomas Baumgart
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Baumgart 2017-08-07 15:50:53 UTC
Created attachment 107126 [details]
Split editor showing offset of one cent

Gee Backhaus reported:

I am having to consider tax (VAT) for the first time in Kmymoney and have
found a rounding error. I followed the excellent instructions in your pdf
manual and they work like a dream until there's a number that it is unable
to resolve.

*Example*: I am entering the gross amount of 17.07 and the associated tax
amount is 20%.
On a calculator 17.07 gives 14.225 + 2.845
In Kmymoney 17.07 gives 14.22 + 2.84 (automatically as shown in the
attached). So, Kmymoney appears to round each value down and leave me with
a discrepancy - which I am also unable to override manually.

This is on 4.7.2 but is also in current git master.
Comment 1 Thomas Baumgart 2017-08-07 15:53:54 UTC
The problem stems from the internal calculation of the tax part. It is always calculated by subtracting the net value from the gross value. The problem is, that it does not adjust the net value to the rounded one before doing the subtraction. This in fact leaves the tax part as 2.855 in your example which is then rounded again.

It should round 14.225 to 14.22 and then doing the subtraction to 17.07-14.22 which results in 2.85 and everyone is happy. Hey, you found a bug!  And a rather old one: it lives there for more than 10 years now. Congrats.
Comment 2 Thomas Baumgart 2017-08-07 18:20:12 UTC
Git commit eb7e02dd0fc840fa44d5ad1d514060d9637468f7 by Thomas Baumgart.
Committed on 07/08/2017 at 18:15.
Pushed by tbaumgart into branch 'master'.

Fix VAT assignment rounding problems

Rounding problems led to non-balanced transactions. This change avoids
such a situation.
FIXED-IN: 5.0
CCMAIL: geebackhouse@gmail.com

M  +3    -3    kmymoney/mymoney/mymoneyfile.cpp

https://commits.kde.org/kmymoney/eb7e02dd0fc840fa44d5ad1d514060d9637468f7
Comment 3 Ralf Habacker 2017-08-08 07:03:39 UTC
Git commit 3bfcf56a8e2ba1fd5a8fba6b235d0ceb94ca3c8c by Ralf Habacker, on behalf of Thomas Baumgart.
Committed on 08/08/2017 at 07:02.
Pushed by habacker into branch '4.8'.

Fix VAT assignment rounding problems

Rounding problems led to non-balanced transactions. This change avoids
such a situation.
FIXED-IN: 5.0
CCMAIL: geebackhouse@gmail.com
(cherry picked from commit eb7e02dd0fc840fa44d5ad1d514060d9637468f7)

M  +3    -3    kmymoney/mymoney/mymoneyfile.cpp

https://commits.kde.org/kmymoney/3bfcf56a8e2ba1fd5a8fba6b235d0ceb94ca3c8c