From 0a9b998a9cba27a0be036954c8451eb8bb3e498c Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Sun, 29 Dec 2019 14:26:05 -0700 Subject: [PATCH] fix formatting non-fraction amounts --- lib/App/HomeBank2Ledger/Formatter/Beancount.pm | 6 +++++- lib/App/HomeBank2Ledger/Formatter/Ledger.pm | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index 748a0bf..dc98934 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -278,9 +278,13 @@ sub _format_amount { my $format = "\% .$commodity->{frac}f"; my ($whole, $fraction) = split(/\./, sprintf($format, $amount)); + $fraction ||= 0; # beancount doesn't support different notations - my $num = join('.', commify($whole), $fraction); + my $num = commify($whole); + if ($commodity->{frac}) { + $num .= ".$fraction"; + } $num = "$num $commodity->{iso}"; diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index 464fa04..300a832 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -319,8 +319,12 @@ sub _format_amount { my $format = "\% .$commodity->{frac}f"; my ($whole, $fraction) = split(/\./, sprintf($format, $amount)); + $fraction ||= 0; - my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction); + my $num = commify($whole, $commodity->{gchar}); + if ($commodity->{frac}) { + $num .= $commodity->{dchar} . $fraction; + } my $symbol = $commodity->{symbol}; $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; -- 2.45.2