[GNC] Rounding & formulas
Peter West
lists at pbw.id.au
Mon Dec 21 22:23:41 EST 2020
Just by the way, there’s a fascinating illustration of the floating point problem in the history of TeX. When Knuth and co. wrote TeX, the intention was that a TeX document would reproduce identical printed documents irrespective of the hardware it ran on. After a while, it was reported that this was not true. Documents designed and produced on one system produced different results on another system.
The problem was that the layout calculations were being done in floating point, and the floating point hardware implementation was a little different on different systems. (Such hardware is much more standardised now.) The solution was to define the layout space as an integral number of thousandths of a point. Problem solved. Ah, the wonder of integers.
Peter
--
Peter West
pbw at pbw.id.au
“My soul magnifies the Lord, and my spirit rejoices in God my Saviour…”
> On 22 Dec 2020, at 1:13 pm, Peter West <lists at pbw.id.au> wrote:
>
> 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
>>
>
> _______________________________________________
> 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