[kmymoney] [Bug 402750] New: Rounding problems with stock split factor cause crashes and errors

Mark Thomas bugzilla_noreply at kde.org
Tue Jan 1 10:27:10 GMT 2019


https://bugs.kde.org/show_bug.cgi?id=402750

            Bug ID: 402750
           Summary: Rounding problems with stock split factor cause
                    crashes and errors
           Product: kmymoney
           Version: 5.0.1
          Platform: Ubuntu Packages
                OS: Linux
            Status: REPORTED
          Severity: major
          Priority: NOR
         Component: general
          Assignee: kmymoney-devel at kde.org
          Reporter: marks.subs at gmail.com
  Target Milestone: ---

Created attachment 117222
  --> https://bugs.kde.org/attachment.cgi?id=117222&action=edit
backtrace of divide by zero

SUMMARY

kMyMoney incorrectly rounds the factor for a stock "Split Shares" activity
instead of the resulting balance causing divide-by-zero or incorrect
calculations.


STEPS TO REPRODUCE
1. Under Investments create a stock with the fraction set to 1 (ie: 1/1, whole
stocks).
2. In the ledger create a new "Buy Shares" activity for the stock with any
quantity and price.
3. In the ledger create a new "Split Shares" activity for the stock and set the
ratio to less than 0.5 (eg: 0.166667 for a 1-for-6 share consolidation)

OBSERVED RESULT

On entering the split shares activity kMyMoney will immediately crash with a
divide-by-zero exception, see attached stack trace.

EXPECTED RESULT

A ratio less than 1 should create a share consolidation, decreasing the balance
of shares by the given factor.

Alternatively in step 3 enter the ratio of 1.5 for a 3-for-2 stock split and
observe that kMyMoney rounds the factor up to 2 and incorrectly doubles the
balance.

The rounding for the share fraction should be done later on the new balance of
shares after the split factor is applied and not on the factor itself.


SOFTWARE/OS VERSIONS

kmymoney 5.0.1-2 Kubuntu package and 5.0.2 compiled from git.

Linux/KDE Plasma: Kubuntu 18.04 LTS 
KDE Plasma Version: 5.12.7
KDE Frameworks Version: 5.44.0
Qt Version: 5.9.5

ADDITIONAL INFORMATION

I have a stock that has had a 1-for-6 share consolidation so needed to reduce
the quantity down by the ratio of one for every 6 currently held.

Entering this as a "Split Shares" activity with a factor of 0.16667 (ie: 1
divided by 6) causes a divide by zero floating point exception.  

The critical point is that the stock is defined with  a 1/1 fraction (ie: whole
stocks) and that this causes the split factor in the activity to be rounded
down to zero.

This rounding  is also an issue with normal splits of whole stocks, for example
a 3:2 split entered as factor 1.5 as per the manual is rounded up to 2.

I suspect that other unusual splits may have rounding problems with other
fractions.

The problem code appears to be in in
kmymoney/dialogs/investtransactioneditor.cpp where
InvestTransactionEditor::createTransaction() calls:

s0.setShares(MyMoneyMoney(s0.shares().convertDenominator(securityFraction,
roundingMethod)));

with securityFraction is 1 but the value in s0 is the factor, not the total
quantity of shares, and needs to keep the precision it was entered with.

The rounding would need to be moved to the split calculation on the share
balance in KGlobalLedgerViewPrivate::loadView() in
kmymoney/views/kgloballedgerview_p.h

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the KMyMoney-devel mailing list