[GNC] Rounding & formulas

Peter West pbw at pbw.id.au
Mon Dec 21 07:14:21 EST 2020


There’s no rounding as such involved in the formulae. The timing will only matter if total_amount changes between the two calculations, which I assume it will not do. If x/2, when x is an integer (be it number of cents or number of pennies or whatever), does not give identical results for the same x whenever it is executed, something is seriously wrong.

If x is a floating point number, odd things can happen. Even so, for the same x, the result must be constant. The developers should be able to clarify all of this.

Peter
--
Peter West
pbw at pbw.id.au
“Blessed are you among women, and blessed is the fruit of your womb!”

> On 21 Dec 2020, at 9:24 pm, Fred Bone <Fred.Bone at dial.pipex.com> wrote:
> 
> On 21 December 2020 at 12:12, Peter West said:
> 
>> I don’t understand why "total_amount-(total_amount/2)” doesn’t work.
>> I’m assuming that two formulae are used: total_amount/2 &
>> total_amount-(total_amount/2), as the OP specifies.
>> 
>> If the amount is odd, the first should be (given consistent truncation of
>> the dividend by integer division) equivalent to (total_amount -1) / 2,
>> which when subtracted from total_amount will leave an odd result. If it
>> doesn’t do this, then there is a serious problem with Gnucash
>> arithmetic.
> 
> That obviously depends on when the rounding occurs.
> 
> The OP's example suggests it happens as late as possible, as one would 
> reasonably expect. If so, adding 0.005 to whichever of the two is 
> required to be rounded up is guaranteed to produce the desired effect.
> 
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.



More information about the gnucash-user mailing list