From: G. Richardson Date: Mon, 26 Oct 2015 08:55:59 +0000 (+0100) Subject: format_amount - negative 0 vermeiden X-Git-Tag: release-3.4.1~623 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bf19eeda5d339c95bde5334727bd9a6802375a8d;p=kivitendo-erp.git format_amount - negative 0 vermeiden Ist eine Zahl z.B. -0.002, und wird auf 2 Stellen gerundet, so wird erst das Minuszeichen gemerkt, dann gerundet (0.00), und schießlich wird das Minus wieder hinzugefügt, dadurch bekommt man -0.00. Mit diesem Patch wird das Minus-Zeichen entfernt wenn die gerundete Zahl genau 0 ergibt. --- diff --git a/SL/Form.pm b/SL/Form.pm index 9045d78ca..35b21d5a2 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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 diff --git a/t/form/format_amount.t b/t/form/format_amount.t index 229c88cd5..8de39a2e3 100644 --- a/t/form/format_amount.t +++ b/t/form/format_amount.t @@ -51,6 +51,8 @@ is($::form->format_amount($config, 10, -2), '10,00' , 'autotrim does not harm in is($::form->format_amount($config, 10, 0), '10', 'autotrim does not harm integers 4'); is($::form->format_amount($config, 0, 0), '0' , 'trivial zero'); +is($::form->format_amount($config, -0.002, 2), '0,00' , 'negative zero'); +is($::form->format_amount($config, -0.002, 3), '-0,002' , 'negative zero'); # dash stuff