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

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20170916161612.29960.62319%40celery-worker-108.ash1.bb-inf.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to