From: Charles McGarvey Date: Sun, 29 Dec 2019 21:26:05 +0000 (-0700) Subject: fix formatting non-fraction amounts X-Git-Tag: v0.007~1 X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=0a9b998a9cba27a0be036954c8451eb8bb3e498c;p=chaz%2Fhomebank2ledger fix formatting non-fraction amounts --- 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]/;