Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8edb2ea1

Von Sven Schöling vor etwa 12 Jahren hinzugefügt

  • ID 8edb2ea1ebaa8cb4961aba4e9b5dd96c0191d338
  • Vorgänger 7d29de1c
  • Nachfolger 215d49a8

format_amount bug: Bei places == 0 wurden trailing 0 abgeschnitten

Unterschiede anzeigen:

SL/Form.pm
878 878
  # this is easy to confuse, so keep in mind: before this comment no s///, m//, concat or other strong ops on
879 879
  # $amount. after this comment no +,-,*,/,abs. it will only introduce subtle bugs.
880 880

  
881
  $amount =~ s/0*$//;                                                    # cull trailing 0s
881
  $amount =~ s/0*$// unless defined $places && $places == 0;             # cull trailing 0s
882 882

  
883 883
  my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
884 884
  my @p = split(/\./, $amount);                                          # split amount at decimal point
t/form/format_amount.t
32 32
is($::form->format_amount($config, 1, -2), '1.00', 'negative places 3');
33 33

  
34 34
# bugs amd edge cases
35
$config->{numberformat} = '1.000,00';
35 36

  
36 37
is($::form->format_amount({ numberformat => '1.000,00' }, 0.00005), '0,00005', 'messing with small numbers and no precision');
37 38
is($::form->format_amount({ numberformat => '1.000,00' }, undef), '0', 'undef');
......
44 45

  
45 46
is($::form->format_amount($config, 1.00), '1', 'autotrim to 0 places');
46 47

  
48
is($::form->format_amount($config, 10), '10', 'autotrim does not harm integers');
49
is($::form->format_amount($config, 10, 2), '10,00' , 'autotrim does not harm integers 2');
50
is($::form->format_amount($config, 10, -2), '10,00' , 'autotrim does not harm integers 3');
51
is($::form->format_amount($config, 10, 0), '10', 'autotrim does not harm integers 4');
52

  
53
is($::form->format_amount($config, 0, 0), '0' , 'trivial zero');
47 54

  
48 55
# dash stuff
49 56

  

Auch abrufbar als: Unified diff