Formatting commodity output with the format commodity directive

25 views
Skip to first unread message

Jasel17212

unread,
Oct 31, 2021, 1:43:48 PMOct 31
to Ledger

 TL;DR
I would like to use the -X flag to display balances in an alternative currency with Ledger 3.2.1-20200518. The conversion functionality works just fine, but the format directive isn’t working for me.

Everything in my journal is in USD, but I would like to be able to show my balances in AUD. To do this, I simply added the following line to my price database.

P 2021/10/30 16:22:00 AUD $0.75244225

Based on information in the manual I should be able to use the format commodity directive to handle the formatting for a given commodity, so I’ve set mine up as follows:

commodity AUD
   note Aussie Dollars
   format A1,000.00

When I run ledger, the balances are properly calculated and displayed in AUD, but the formatting is not honored.

ledger -f register.ldg --price-db price_db.txt -V --strict –explicit bal Bank -X AUD

The output looks looks like this:

AUD100000 Assets:Banking
 AUD50000   Acct1
 AUD20000   Acct2
 AUD30000   Acct3

What am I missing?

Thanks
JL

Jasel17212

unread,
Oct 31, 2021, 7:22:57 PMOct 31
to Ledger

 I’ve searched and searched, and I can’t find a resolution to this issue. In fact, I’m not even sure, at this point, that the format commodity directive is actually implemented in the software to function as outlined in the manual.

That said, I did come up with a usable workaround. It’s kludgy, but it produces the desired output.

This can be implemented in a number of different ways, but I did it by creating a currency.ldg journal file and including it before my transaction journals. In that file, I created dummy entries for each currency that I want to use in my reporting:

2020/01/01 * Australian Dollar
     Equity:Opening Balances
     Assets:Currency 1,000.00 AUD @ $1,000.00
2020/01/01 * Australian Dollar
     Equity:Opening Balances
     Assets:Currency -1,000.00 AUD @ $1,000.00

The two entries cancel each other out while simultaneously telling Ledger how to format the AUR commodity.

The next step, as outlined in my first post, is to update the price database:

P 2021/10/30 16:22:00 AUD $0.75244225

Once that’s complete, I can run my report again:

ledger -f register.ldg --price-db price_db.txt -V --strict –explicit bal Bank -X AUD

This time I get the desired output:

100,000 AUD Assets:Banking
50,000 AUD Acct1
20,000 AUD Acct2
30,000 AUD Acct3

There may very well be a cleaner way to do this, but this approach does seem to effectively work around my initial problem. If you have thoughts on a better way to do this, feel free to share your ideas.

Thanks
JL

Martin Michlmayr

unread,
Oct 31, 2021, 7:28:29 PMOct 31
to ledge...@googlegroups.com
* Jasel17212 <ja...@thelittonfamily.com> [2021-10-31 16:22]:
> There may very well be a cleaner way to do this, but this approach
> does seem to effectively work around my initial problem. If you have
> thoughts on a better way to do this, feel free to share your ideas.

Add this to your file:

D 1,000.00 AUD

--
Martin Michlmayr
https://www.cyrius.com/

Jasel17212

unread,
Oct 31, 2021, 7:33:53 PMOct 31
to Ledger
That's MUCH cleaner.

Thanks!

Reply all
Reply to author
Forward
0 new messages