I think the problem is that with late rounding the formula may not work.
Suppose the amount is 0.21.
Compute amount/2 exactly: 0.21/2=0.105
Subtract from amount 0.21 - 0.105=0.105
For a fixed rounding scheme both will either be 0.11 or 0.10 and the sum
will be 0.22, respectively, 0.20. Neither is the desired 0.21.

If the sum is to be correct, one could try to implement amount1 =
round(amount/2). amount2 = amount - amount1.

Dale

On Mon, Dec 21, 2020 at 3:41 PM Peter West <p...@pbw.id.au> wrote:

> 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
> p...@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.b...@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@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.
>
> _______________________________________________
> gnucash-user mailing list
> gnucash-user@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.
>
_______________________________________________
gnucash-user mailing list
gnucash-user@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.

Reply via email to