Thanks for explaination.

It seems that the implicit rounding occurs not only in "PRINT", but also
has effect on balance calculation:


1970-01-01 open Assets:Cash
1970-01-01 open Assets:Positions
1970-01-01 open Expenses:Financial:Commissions

2018-03-29 * "Buy 10 BILI"
  Assets:Cash
  Assets:Positions                 10 BILI {11.4899 USD, 2018-03-29} @ 11.4899 
USD
  Expenses:Financial:Commissions  0.1 USD

2018-04-01 balance Assets:Cash -114.9990 USD


The last balance assertion fails:


Balance failed for 'Assets:Cash': expected -114.9990 USD != accumulated -115.0 
USD (0.0010 too little)


Is there a way to turn off the implicit rounding without padding 0.1 USD
to 0.1000 USD?




2018-04-04 01:53:19 Martin Blais <[email protected]>:
> This is correct.
> 
> First, the PRINT command of the shell (which is what I believe you're using) 
> will render the numbers at their stored
> precision:
> https://bitbucket.org/blais/beancount/src/4a3995617e7df5ffa3377711382c7ad2f9d8935b/beancount/query/query_execute.py?at=
> default&fileviewer=file-view-default#query_execute.py-92
> 
> I kept it this way originally because PRINT was intended for debugging, so 
> rounding using the most common precision
> seen in the file seemed it would create problems with interpreting the data.  
> I'm not 100% this was the right choice.
> 
> Second, about rounding: by default the tolerance used is that which is 
> inferred on the transaction:
> https://bitbucket.org/blais/beancount/src/4a3995617e7df5ffa3377711382c7ad2f9d8935b/beancount/core/interpolate.py?at=
> default&fileviewer=file-view-default#interpolate.py-324
> 
> The comment you're referring to applies to the case where a tolerance cannot 
> be inferred at all (like in the first
> example in that section). In that case, no rounding occurs. I'll clarify the 
> docs.
> 
> (This hurts my head too.)
> 
> 
> 
> 
> On Sun, Apr 1, 2018 at 5:13 AM, Zhuoyun Wei <[email protected]> wrote:
> 
>     Hi Martin,
> 
>     Beancount seems to round inferred numbers by default:
> 
>     1970-01-01 open Assets:Cash
>     1970-01-01 open Assets:Positions
>     1970-01-01 open Expenses:Financial:Commissions
> 
>     2018-03-29 * "Buy 10 BILI"
>       Assets:Cash
>       Assets:Positions                 10 BILI {11.4899 USD, 2018-03-29} @ 
> 11.4899 USD
>       Expenses:Financial:Commissions  0.1 USD
> 
>     turns into:
> 
>     2018-03-29 * "Buy 10 BILI"
>       Assets:Cash                     -115.0 USD
>       Assets:Positions                    10 BILI {11.4899 USD, 2018-03-29} @ 
> 11.4899 USD
>       Expenses:Financial:Commissions     0.1 USD
> 
>     The full-precision number for Assets:Cash should be -114.9990 USD, but
>     it was incorrectly rounded to -115.0 USD.
> 
>     In the documentation
>     
> https://docs.google.com/document/d/1lgHxUUEY-UVEgoF6cupz2f_7v7vEF7fiJyiSlYYlhOo/
>     section "Precision of Inferred Numbers":
> 
>     > If the default tolerance is not overridden in the input file—and
>     > therefore is zero—the full precision will be used; no rounding occurs.
> 
>     In the minimal example above, the precision seems to be inferred from
>     0.1 USD commission. If I change the input file, changing commission from
>     0.1 USD to 0.1000 USD, the output is correct:
> 
>     2018-03-29 * "Buy 10 BILI"
>       Assets:Cash                     -114.9990 USD
>       Assets:Positions                       10 BILI {11.4899 USD, 
> 2018-03-29} @ 11.4899 USD
>       Expenses:Financial:Commissions     0.1000 USD
> 
>     My broker-dealer returns the commission as 0.1 USD because it is a
>     floating point number in JSON (you cannot end numbers with zeros). But
>     behind the scenes it calculates the cash balance with the full-precision
>     numbers (e.g. 0.1000 USD). After a few transactions, the balance of
>     Assets:Cash has a difference of more than 0.005 USD with the
>     broker-dealer and thus fails the balance assertion.
> 
>     Is there a way to turn off the implicit rounding without padding 0.1 USD
>     to 0.1000 USD in the input file?
> 
>     I am using tagged release 2.0.0.
>    
> 
>     --
>     Zhuoyun Wei
> 
>     --
>     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 beancount+unsubscribe@
>     googlegroups.com.
>     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/20180401091341.GA26139%
>     40tarball.wzyboy.org.
>     For more options, visit https://groups.google.com/d/optout.
> 
> 
> --
> 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/
> CAK21%2BhPeexbubq8dEjvYOYuKd1tMOXh36CuByWPAG_yJa%3Df7zw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Zhuoyun Wei

-- 
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/20180404064534.GA19470%40herus.wzyboy.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: PGP signature

Reply via email to