]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Form.pm
SelfTest um Testfall ac.amount == ar.netamount ergänzt
[mfinanz.git] / SL / Form.pm
index 9045d78ca3a2c719b205f4d61d5a3b10e83a2b01..c59669c41a77a075a8fe873f3e84b2783edbeaee 100644 (file)
@@ -822,6 +822,7 @@ sub format_amount {
   my $force_places = defined $places && $places >= 0;
 
   $amount = $self->round_amount($amount, abs $places) if $force_places;
+  $neg    = 0 if $amount == 0; # don't show negative zero
   $amount = sprintf "%.*f", ($force_places ? $places : 10), abs $amount; # 6 is default for %fa
 
   # before the sprintf amount was a number, afterwards it's a string. because of the dynamic nature of perl
@@ -981,7 +982,9 @@ sub round_amount {
   # part. If an overflow occurs then apply that overflow to the part
   # before the decimal sign as well using integer arithmetic again.
 
-  my $amount_str = sprintf '%.*f', $places + 10, abs($amount);
+  my $int_amount = int(abs $amount);
+  my $str_places = max(min(10, 16 - length("$int_amount") - $places), $places);
+  my $amount_str = sprintf '%.*f', $places + $str_places, abs($amount);
 
   return $amount unless $amount_str =~ m{^(\d+)\.(\d+)$};