Number of decimal places with beanprice

112 views
Skip to first unread message

Alen Šiljak

unread,
May 30, 2025, 11:10:05 AM5/30/25
to Beancount
Hi! I've set up beanprice to fetch prices and that seems to work. I've also adapted some of my price sources to work with beancount. These are publicly available as as-price-download on github/pypi.

When running directly
```sh
bean-price -e "AUD:pricedl.beanprice.yahoo/ASX:VHY"
```
the price comes out as expected
```
2025-05-30 price ASX:VHY                             74.33 AUD
```
But, when reading the metadata from the book
```
bean-price -v ..\book.bean > ..\prices\prices.current.bean
```
the prices are coming out like this:
```
2025-05-30 price BLV                    67.6500000000000000000000000000 USD
2025-05-30 price BND                    72.6350000000000000000000000000 USD
2025-05-29 price BRF                    14.5922000000000000000000000000 USD
2025-05-30 price BSV                    78.2699966430664062500000000000 USD
2025-05-30 price CEMB                   44.8699989318847656250000000000 USD
2025-05-30 price CQE_AX                 2.960000038146972656250000000 AUD
```
These are from two different sources. Mine has 4 decimals, so likely using a different API.
Is there a way to limit the number of decimal places and/or to get rid of the zeros?
In the price source I've written, the price is Decimal type. So, the output and the conversion to string happens somewhere in beanprice, I assume?

Somebody elsewhere suggested that this is due to the existing prices and inference. I will try to experiment with one symbol.

Any hints highly appreciated!

Chary Ev2geny

unread,
Jun 3, 2025, 6:24:47 PM6/3/25
to Beancount
Hi,

I also saw similar problem, so I now documented on how to reproduce it

https://github.com/beancount/beanprice/issues/116

Regards.

Alen Šiljak

unread,
Jun 3, 2025, 7:17:54 PM6/3/25
to Beancount
Thank you for that analysis! 
For reference, I will also copy here the reply I added to that issue:

Thanks for elaborating! I had the same issue. However, I searched for decimal places
```sql
select * where round(number, 6) != number
```
and there was no records with that many decimal places. I looked for both `number` and `cost_number`.
I was debugging the `print` function but did not really figure out why all the prices were maxed-out with zeros. The currency precision was different for different currencies, while prices were all with almost the same number of decimal places.
After I fixed the price source to return the decimals as reported on the exchange (the source I was testing with was returning some crazy amounts with multiple decimals, but max. 6, not 18), the places were padded with 0's.
After reading your description, I assume the decimal places were jacked-up by implicit prices, since I'm using
```
plugin "beancount.plugins.implicit_prices"
```
in my book. But that is still just an assumption.

Based on the recent check-ins, Martin is working on the precision setting so that might eventually resolve the problem.

As a workaround, I wrote a simple script that strips the right-most zeros from the prices in the generated price file. This will work for now, as I'm focusing on completing the importers and other price sources.

Chary Ev2geny

unread,
Jun 11, 2025, 5:38:47 AM6/11/25
to Beancount

I have create a simple PR 120, which I think fixes this (at least partially)

One can try it 

Reply all
Reply to author
Forward
0 new messages