I don't mind excessive decimal points in my bookkeeping but I'd like to be able to render reports and control the reported precision there. So I implemented __round__() on Amount, and added Amount to the signature of the bean-query round() function in query_env.py (happy to offer PRs after I am sure it's correct).
The round() function now works for me in bean-query, and some debugging confirms that internally the Amount number gets rounded, but for some reason the DisplayContext still seems to get the idea my numbers have lots of points of precision. If I wrap the round() with a str() to force an early conversion to a string, one can see that the numbers have been rounded as expected. Compare:
beanquery> SELECT date, maxwidth(narration, 20), account, 10, round(cost(position), 4) as amount FROM has_account("PnL") AND year(date) = 2021 WHERE account="Income:PnL" AND abs(number) < 100 limit 5
date maxwidth(narration account 10 amount
---------- ------------------ ---------- -- --------------------------------
2021-05-10 Send 0.0001 XCH Income:PnL 10 -0.1000000000000000000000000 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 5.3300000000000000000000000 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 5.3300000000000000000000000 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 7.4600000000000000000000000 USD
2021-09-03 Fees for Buy [...] Income:PnL 10 1.6800000000000000000000000 USD
beanquery> SELECT date, maxwidth(narration, 20), account, 10, str(round(cost(position), 4)) as amount FROM has_account("PnL") AND year(date) = 2021 WHERE account="Income:PnL" AND abs(number) < 100 limit 5
date maxwidth(narration account 10 amount
---------- ------------------ ---------- -- -----------
2021-05-10 Send 0.0001 XCH Income:PnL 10 -0.1000 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 5.3300 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 5.3300 USD
2021-08-31 Fees for Buy [...] Income:PnL 10 7.4600 USD
2021-09-03 Fees for Buy [...] Income:PnL 10 1.6800 USD
I've dug around the DisplayContext updating code and can't figure out what's going on. Any ideas?
eric