On 08/08/2020 01:11, nugget wrote:
> thanks for your replies. 
> I actually thought Decimal() is meant to turn a float into something
> nice for bookkeeping (that was my interpretation of the docs)
> My underlying question is what is the intended way to handle rounding
> errors? I.e. when splitting up a transaction into multiple transactions.
> say distribute a yearly transaction over 12 months or a weekly one over
> 7 days. 
> 
> Naively, I would take  1 CHF and divide it by 12, and make 12
> transactions. I dislike having my posting look like
> "0.08333333333333332870740406406184774823486804962158203125".But simply
> rounding will introduce an error of 4%:
> round(1/12,2) = 0.8, and 
> 12*0.8 = 0.96
> 
> My next best idea is to make sure that of the transactions covers the error:
> round(1 - 11*round(1/12)) or something. but also this looks too ugly to
> be a "correct" way. What would you recommend?

I think you are looking at this from the wrong perspective. Thus you see
a problem that is not there. beancount ise designed to record real
financial transactions. These involve the exchange of exactly defined
quantities of something, represented by exact decimal numbers (I think
the introduction of the Python documentation covers this nicely for
someone not into the technicalities
https://docs.python.org/3.8/library/decimal.html). For example, if you
split a 1 CHF expense with two friends, two of you will have to pay 0.33
CHF but one will have to pay 0.34 CHF: there is not way you can split a
CHF with smaller granularity.

Of course, you see that the fact that you cannot split CHF with smaller
granularity leads to some "funny" situations: what if I need to split a
0.02 CHF expense in three tranches? There is no way of doing it.

Who designed the Swiss monetary system (and all other monetary systems)
decided that rounding errors (and accumulation of rounding errors) at
the 0.01 CHF level is acceptable.

What this means is that the tool you use to amortize these amounts over
some time units (or that does other divisions) needs to be aware of this
characteristic of real financial transactions. In the case of dividing 1
CHF over 12 months, the best thing you can do is to book 0.08 CHF for 8
months and 0.09 CHF for 4 months. I don't know if there is a library
function somewhere that can do this computation for you.

Please note that this has noting to do with beancount or with Decimal
numbers, but only with the physical basis of the monetary systems (the
granularity of financial transactions is determine by the smaller coin
issued).

You can decide to write your transactions is some form of virtual Swiss
Franc that has higher resolution, but this only moves the problem to a
different decimal place, because you still need to decide what this
resolution is going to be and proper deal with rounding that that level
to have the transactions balance.

Cheers,
Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/75ea7fbf-5072-5201-482a-c0424f9fab7e%40grinta.net.

Reply via email to