Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fcc1d512

Von Thomas Heck vor etwa 12 Jahren hinzugefügt

  • ID fcc1d512a5e2cd9db53702fea9ef83684aa0f2f3
  • Vorgänger 0f988add
  • Nachfolger a1a9bb96

SL::Form::format_amount formatiert Zahlen auch aus der Exponentialschreibweise.

+Tests für SL::Form::format_amount
fixt #1904

Unterschiede anzeigen:

SL/Form.pm
871 871
    $amount = 0;
872 872
  }
873 873

  
874
  $amount *= 1;
875

  
874 876
  # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
875 877

  
876 878
  my $neg = ($amount =~ s/^-//);
t/form/format_amount.t
1
use strict;
2
use Test::More;
3

  
4
use lib 't';
5

  
6
use_ok('SL::Form');
7
require_ok('SL::Form');
8

  
9

  
10
package LxDebugMock;
11
sub enter_sub {};
12
sub leave_sub {};
13

  
14
$main::lxdebug = bless({}, 'LxDebugMock');
15

  
16
package main;
17

  
18

  
19
my $form = Form->new();
20

  
21

  
22
my $config = {};
23

  
24

  
25
$config->{numberformat} = '1.000,00';
26

  
27
is($form->format_amount($config, '1e1', 2), '10,00', 'blaa');
28
is($form->format_amount($config, 1000, 2), '1.000,00', 'blaa');
29
is($form->format_amount($config, 1000.1234, 2), '1.000,12', 'blaa');
30
is($form->format_amount($config, 1000000000.1234, 2), '1.000.000.000,12', 'blaa');
31
is($form->format_amount($config, -1000000000.1234, 2), '-1.000.000.000,12', 'blaa');
32

  
33

  
34
$config->{numberformat} = '1,000.00';
35

  
36
is($form->format_amount($config, '1e1', 2), '10.00', 'blaa');
37
is($form->format_amount($config, 1000, 2), '1,000.00', 'blaa');
38
is($form->format_amount($config, 1000.1234, 2), '1,000.12', 'blaa');
39
is($form->format_amount($config, 1000000000.1234, 2), '1,000,000,000.12', 'blaa');
40
is($form->format_amount($config, -1000000000.1234, 2), '-1,000,000,000.12', 'blaa');
41

  
42
done_testing;
43

  
44
1;

Auch abrufbar als: Unified diff