Hi all,
i get these very long decimal numbers when using the Decimal() method. See 
my minimal example. How can I fix this? rounding to two digits seems not to 
be the solution. Thanks!

2020-01-01 * "format" "1"
  myAccount  1 CHF

2020-01-01 * "format" "1/9"
  myAccount  0.111111111111111104943205418749130330979824066162109375 CHF

2020-01-01 * "format" "round(1/9,2)"
  myAccount  0.11000000000000000055511151231257827021181583404541015625 CHF

2020-01-01 * "format" "10000"
  myAccount  10000 CHF

minimal example code:
from beancount.core import data, amount
from beancount.core.amount import D
from beancount.parser import printer

number = [1,1/9,round(1/9,2),10000]
narration=['1','1/9','round(1/9,2)','10000']

for i, num in enumerate(number):
    num_ = D(num)

    amount_ = amount.Amount(D(num),'CHF')
    P1 = data.Posting(account = 'myAccount',
                    units = amount_,
                    cost = None, price = None, flag = None, meta = None)
    P2 = data.Posting(account = 'myAccount',
                    units = None,
                    cost = None, price = None, flag = None, meta = None)
    T=data.Transaction(meta=None,
                    date='2020-01-01',
                    flag="*",
                    payee='format',
                    narration=narration[i],
                    tags=data.EMPTY_SET,
                    links=data.EMPTY_SET,
                    postings=[P1])
    printer.print_entry(T)



-- 
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/94143347-2bcb-42e6-afa3-42c9bdc50964o%40googlegroups.com.

Reply via email to