Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bf19eeda

Von Kivitendo Admin vor mehr als 8 Jahren hinzugefügt

  • ID bf19eeda5d339c95bde5334727bd9a6802375a8d
  • Vorgänger 247a3b82
  • Nachfolger 7915128c

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.

Unterschiede anzeigen:

SL/Form.pm
822 822
  my $force_places = defined $places && $places >= 0;
823 823

  
824 824
  $amount = $self->round_amount($amount, abs $places) if $force_places;
825
  $neg    = 0 if $amount == 0; # don't show negative zero
825 826
  $amount = sprintf "%.*f", ($force_places ? $places : 10), abs $amount; # 6 is default for %fa
826 827

  
827 828
  # before the sprintf amount was a number, afterwards it's a string. because of the dynamic nature of perl
t/form/format_amount.t
51 51
is($::form->format_amount($config, 10, 0), '10', 'autotrim does not harm integers 4');
52 52

  
53 53
is($::form->format_amount($config, 0, 0), '0' , 'trivial zero');
54
is($::form->format_amount($config, -0.002, 2), '0,00' , 'negative zero');
55
is($::form->format_amount($config, -0.002, 3), '-0,002' , 'negative zero');
54 56

  
55 57
# dash stuff
56 58

  

Auch abrufbar als: Unified diff