[Kmymoney-devel] [Android Port] Help with computing the account balance

Eric Bonney mailinglists at vanhlebarsoftware.com
Wed Oct 10 12:56:29 UTC 2012


Thanks everyone for the patience and the help, I think I have a fairly good
grasp now on what changes I need to make to get things rolling again. It is
quit shameful the amount of basic math skills you lose when you don't use
them, but that is an entirely different story. :)

Thomas:

Thanks for the warning on the rounding issues, I saw this earlier when
first developing the port and had come up with a good work around but it
won't work now, so I will have to look at the library and see if something
different will work better. I am sure there are ways to import C libraries
into my project but I am not sure how, so for now I will be sticking to
trying to implement what has been done in Java.

Thanks again to everyone for all the help on this project, it is moving
along very well finally and hopefully will become more solid in the coming
months.

-Eric

On Wed, Oct 10, 2012 at 1:41 AM, Thomas Baumgart <thb at net-bembel.de> wrote:

> Eric,
>
> basically, Allen explained the math behind the operation, and we all
> remember
> it from school: reducing a fraction. (More inline).
>
> On Tuesday 09 October 2012 17:11:42 you wrote:
>
> > Hi Thomas:
> >
> > Thanks for taking the time to give me such a detailed explanation! Can
> you
> > maybe walk me through a few examples that I can try and use as a
> reference?
> > I finally can see that what I should have been doing from the start is
> take
> > the fraction that is stored in the balance column and just do the
> division
> > on that to come up with my correct "value". That is simple enough and
> > really I am not sure how I missed it.
> >
> > What I can't figure out, even after trying to apply your explanation, is
> > how I am seeing values like below in my balance columns.
> >
> > balance          balanceFormatted
> > -3133/25               -125.32
> > 726071/50          14521.42
> > 66919/25              2676.76
> >
> > Since I know most of the time I have the actual value from the user as a
> > string, how to I take that value and apply the formatMoney() methods to
> get
> > to the fraction side? I am struggling trying to take my -125.32 and
> > returning the fraction of -3133/25.
> >
> > If you can walk me through some of these that would be fantastic!
>
> That is hidden in the MyMoneyMoney string ctor:
>
> MyMoneyMoney::MyMoneyMoney(const QString& pszAmount)
>     : AlkValue(pszAmount, _decimalSeparator)
> {
> }
>
> which calls the AlkValue ctor. It can be used to convert a formatted string
> into a rational value. See testcases in alkvaluetest.cpp, method
> AlkValueTest::stringCtor()
>
> The actual logic is inside the libgmp code in the string assignment e.g.
>
>       d->m_val = qPrintable(QString);    or
>       d->m_val = mpq_class(qPrintable(QString));
>
> where d->m_val is of type "mpq_class" and qPrintable returns a "char *"
>
>       d->m_val.canonicalize()
>
> reduces the rational to its smallest representation by removing common
> factors
> found in numerator and denominator (
> http://gmplib.org/manual/Rational-Number-
> Functions.html#Rational-Number-Functions).
>
> In case you don't use this library you will have to mimic the logic. Allen
> gave an example on how to do that. Be aware of any rounding problems. They
> usually show up when dealing with multiplication of any sort (multiple
> currencies, share value, etc.) in conjunction with addition. You have been
> warned.
>
> --
>
> Regards
>
> Thomas Baumgart
>
> GPG-FP: E55E D592 F45F 116B 8429   4F99 9C59 DB40 B75D D3BA
> -------------------------------------------------------------
> I used to be a hypochondriac AND a kleptomaniac. So I took something for
> it.
> -------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20121010/a9585c1b/attachment.html>


More information about the KMyMoney-devel mailing list