How to format negative amounts in parentheses and in red?

101 views
Skip to first unread message

ed

unread,
Jun 13, 2010, 6:57:43 AM6/13/10
to Ledger
I have RTFM'd, or at least tried to, I'd like to express negative
totals in parens like so (£123.45) but also have them in red for
display on a screen. I found this example in the group

--format %20(total_expr < 0 ? "(" + -total_expr + ")" : total_expr) %
(depth_spacer)%-(partial_account)\n

which kind of works, it surrounds 0 in parentheses, but I can't see
how to format in red. Some guidance please? (for the master/next
branches)

ed

unread,
Jun 13, 2010, 9:31:34 AM6/13/10
to Ledger
This is partly there

--format %20(total_expr < 0 ? ansify_if("(" + -total_expr+ ")",
red) : total_expr) %(depth_spacer)%-(partial_account)\n

But the negative amounts are not padded, note also the 0 is
parenthesised

£564.00 Assets:Bank:Santander
(£1,000.00) Equity:Opening Balances
£686.00 Expenses
£36.00 O2
£650.00 Salary
(£250.00) Income:Misc
(0)

John Wiegley

unread,
Jun 13, 2010, 5:41:24 PM6/13/10
to ledge...@googlegroups.com
This is what you need, and it's not simple:

ledger -F '%(scrub(display_total) < 0 ? ansify_if(justify("(" + to_string(abs(scrub(display_total))) + ")", 20, 20 + prepend_width, true, false), red) : justify(scrub(display_total), 20, 20 + prepend_width, true, color)) %(!options.flat ? depth_spacer : "")%-(ansify_if(partial_account(options.flat), blue if color))\n%/%$1\n%/--------------------\n' bal

However, this *still* won't change the formatting of amounts within multi-commodity balances.

To implement the kind of report you're thinking of, you'd need to use Python.

John

On Jun 13, 2010, at 9:31 AM, ed wrote:

> This is partly there

ed

unread,
Jun 14, 2010, 5:37:35 AM6/14/10
to Ledger
(Backs away slowly) .... maybe I'll leave it as is for now :-)
Reply all
Reply to author
Forward
0 new messages