[GNC] Rounding & formulas

Peter West lists at pbw.id.au
Mon Dec 21 22:13:46 EST 2020


Granted, but that only applies if total_amount is a floating point number. I didn’t think that one through.

$1.01/2 = 0.505
$1.01 - (1.01/2) = 1.01 - 0.505 = 0.505

Both results rounded = .50

I _never_ used floating point for monetary amounts, for reasons demonstrated above, and I pretty soon discovered that that was the general advice. The only currency that is not integral is Bitcoin. (That opens up a whole new can of worms.) Foreign currency transactions are different, but you would have currency conversion vestibules with integral amounts in and out.

I assume from all of this that floating point is built in with the foundations, so it’s too late to do anything about it now.

However, there is talk of moving to a database, in which case the representation of currency will, one hopes, be as a DECIMAL type, with the appropriate number of decimal places, and the OP's formulae will start to work, as if by magic.

[As an aside, individual cents are now virtual in Australian currency, thanks to the ongoing debasement of same. Only in bank accounts and price books do cents exist. One and two cent pieces were withdrawn from circulation years ago. All cash payments are rounded to the nearest 5 cents.]

Peter
--
Peter West
pbw at pbw.id.au
“My soul magnifies the Lord, and my spirit rejoices in God my Saviour…”

> On 21 Dec 2020, at 2:01 pm, John Ralls <jralls at ceridwen.us> wrote:
> 
> 
> 
>> On Dec 20, 2020, at 6:12 PM, Peter West <lists at pbw.id.au> wrote:
>> 
>> I don’t understand why "total_amount-(total_amount/2)” doesn’t work.
> 
> Maybe because the rounding happens after the whole computation?
> 
> Regards,
> John Ralls
> 



More information about the gnucash-user mailing list