[GNC] Rounding & formulas
Fred Bone
Fred.Bone at dial.pipex.com
Mon Dec 21 06:24:32 EST 2020
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.
More information about the gnucash-user
mailing list