fix formatting non-fraction amounts
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 29 Dec 2019 21:26:05 +0000 (14:26 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 29 Dec 2019 21:26:05 +0000 (14:26 -0700)
lib/App/HomeBank2Ledger/Formatter/Beancount.pm
lib/App/HomeBank2Ledger/Formatter/Ledger.pm

index 748a0bf31ecdcfd2dd71edc413eefc8dd5f512a3..dc9893499e9a8c3186e03410237dcef7e668282d 100644 (file)
@@ -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}";
 
index 464fa04871b730b2177388d1f14d679de9b47281..300a83281788f040c52f751551b77cf0bb4ea3a9 100644 (file)
@@ -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]/;
This page took 0.021621 seconds and 4 git commands to generate.