Issue #194: Use of float numbers in Amount() (blais/beancount)

38 views
Skip to first unread message

Zhuoyun Wei

unread,
Sep 16, 2017, 12:16:13 PM9/16/17
to bean...@googlegroups.com
New issue 194: Use of float numbers in Amount()
https://bitbucket.org/blais/beancount/issues/194/use-of-float-numbers-in-amount

Zhuoyun Wei:

Hi,

I have always been bugged by the fact that in Fava, in almost all
transactions involving currency conversions (that is, every time I pay
with international credit cards), very long fractional
numbers are displayed in postings.

I always thought it's something about DisplayContext and did not dig
into the reasons. Today I am playing with BQL and finally it occurs to
me that float numbers, instead of Decimals, are used somewhere
internally in Beancount.

Observe the float round-off errors:

```
beancount> select date, narration, position, weight where account ~ "Expenses:" and narration ~ "Amazon web services";
date narration position weight
---------- ------------------- --------- ----------------------------------
[...]
2016-07-04 Amazon web services 12.06 USD 80.53000000000000000000000001 CNY
[...]
2017-05-05 Amazon web services 13.04 USD 90.13999999999999999999999999 CNY
```

I can see that in Beancount's docs, Martin always uses "@" syntax to
record currency conversions, like "10 USD @ 1.3 CAD". I, however,
always uses "@@" syntax to record conversions, like "10 USD @@ 65 CNY".
Because on my bank statements there are no currency exchange rates, and
only the numbers in foreign currency and local currency are provided.

Here is how the two transactions in the bean-query examples above look
like in the Beancount input files:

```
2016-07-04 * "Amazon web services"
Liabilities:CMB:CreditCards -80.53 CNY
Expenses:Communications:Internet +12.06 USD @@ 80.53 CNY

2017-05-05 * "Amazon web services"
Liabilities:CMB:CreditCards -90.14 CNY
Expenses:Communications:Internet +13.04 USD @@ 90.14 CNY
```

It seems that Beancoun did not use these numbers directly. Instead, it
uses the quotient of the two numbers to calculate the weight. In this
process, float round-off errors occur.

Responsible: blais
Reply all
Reply to author
Forward
0 new messages