line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::FR::Nums2Words;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28158
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
6
|
use Exporter;
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
63
|
|
6
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $VERSION);
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1033
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => [ qw(
|
11
|
|
|
|
|
|
|
num2word
|
12
|
|
|
|
|
|
|
) ] );
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '1.00';
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @major = (
|
19
|
|
|
|
|
|
|
"",
|
20
|
|
|
|
|
|
|
" mille",
|
21
|
|
|
|
|
|
|
" million",
|
22
|
|
|
|
|
|
|
" milliard",
|
23
|
|
|
|
|
|
|
" trillion",
|
24
|
|
|
|
|
|
|
" quadrillion",
|
25
|
|
|
|
|
|
|
" quintillion"
|
26
|
|
|
|
|
|
|
);
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my @ten = (
|
29
|
|
|
|
|
|
|
"",
|
30
|
|
|
|
|
|
|
" dix",
|
31
|
|
|
|
|
|
|
" vingt",
|
32
|
|
|
|
|
|
|
" trente",
|
33
|
|
|
|
|
|
|
" quarante",
|
34
|
|
|
|
|
|
|
" cinquante",
|
35
|
|
|
|
|
|
|
" soixante",
|
36
|
|
|
|
|
|
|
" soixante-dix",
|
37
|
|
|
|
|
|
|
" quatre-vingt",
|
38
|
|
|
|
|
|
|
" quatre-vingt-dix"
|
39
|
|
|
|
|
|
|
);
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @num = (
|
42
|
|
|
|
|
|
|
"",
|
43
|
|
|
|
|
|
|
" un",
|
44
|
|
|
|
|
|
|
" deux",
|
45
|
|
|
|
|
|
|
" trois",
|
46
|
|
|
|
|
|
|
" quatre",
|
47
|
|
|
|
|
|
|
" cinq",
|
48
|
|
|
|
|
|
|
" six",
|
49
|
|
|
|
|
|
|
" sept",
|
50
|
|
|
|
|
|
|
" huit",
|
51
|
|
|
|
|
|
|
" neuf",
|
52
|
|
|
|
|
|
|
" dix",
|
53
|
|
|
|
|
|
|
" onze",
|
54
|
|
|
|
|
|
|
" douze",
|
55
|
|
|
|
|
|
|
" treize",
|
56
|
|
|
|
|
|
|
" quatorze",
|
57
|
|
|
|
|
|
|
" quinze",
|
58
|
|
|
|
|
|
|
" seize",
|
59
|
|
|
|
|
|
|
" dix-sept",
|
60
|
|
|
|
|
|
|
" dix-huit",
|
61
|
|
|
|
|
|
|
" dix-neuf"
|
62
|
|
|
|
|
|
|
);
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub num2word {
|
65
|
12
|
100
|
|
12
|
0
|
747
|
my @numbers = wantarray ? @_ : shift;
|
66
|
12
|
50
|
|
|
|
33
|
return () unless (@numbers);
|
67
|
|
|
|
|
|
|
|
68
|
12
|
|
|
|
|
21
|
my @results = map { _num2word($_) } @numbers;
|
|
15
|
|
|
|
|
34
|
|
69
|
|
|
|
|
|
|
|
70
|
12
|
100
|
|
|
|
72
|
return wantarray ? @results : $results[0];
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _num2words_less_1000 {
|
74
|
19
|
|
|
19
|
|
23
|
my ($number) = @_;
|
75
|
|
|
|
|
|
|
|
76
|
19
|
|
|
|
|
20
|
my $result;
|
77
|
19
|
100
|
|
|
|
36
|
if ($number % 100 < 20){
|
78
|
|
|
|
|
|
|
# 19 et moins
|
79
|
12
|
|
|
|
|
21
|
$result = $num[$number % 100];
|
80
|
12
|
|
|
|
|
19
|
$number /= 100;
|
81
|
|
|
|
|
|
|
} else {
|
82
|
|
|
|
|
|
|
# 9 et moins
|
83
|
7
|
|
|
|
|
13
|
$result = $num[$number % 10];
|
84
|
7
|
|
|
|
|
8
|
$number /= 10;
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# 90, 80, ... 20
|
87
|
7
|
|
|
|
|
20
|
$result = $ten[$number % 10].$result;
|
88
|
7
|
|
|
|
|
13
|
$number /= 10;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# reste les centaines
|
92
|
|
|
|
|
|
|
# y'en a pas
|
93
|
19
|
100
|
|
|
|
44
|
if (int($number) == 0) { return $result; }
|
|
10
|
|
|
|
|
27
|
|
94
|
|
|
|
|
|
|
|
95
|
9
|
100
|
|
|
|
19
|
if (int($number) == 1) {
|
96
|
|
|
|
|
|
|
# on ne retourne "un cent xxxx" mais "cent xxxx"
|
97
|
3
|
|
|
|
|
10
|
return " cent$result";
|
98
|
|
|
|
|
|
|
} else {
|
99
|
6
|
|
|
|
|
35
|
return $num[$number]." cent".$result;
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _num2word {
|
104
|
15
|
|
|
15
|
|
20
|
my ($number) = @_;
|
105
|
|
|
|
|
|
|
|
106
|
15
|
100
|
|
|
|
38
|
return 'zéro' if ($number == 0);
|
107
|
|
|
|
|
|
|
|
108
|
14
|
|
|
|
|
23
|
my $prefix = '';
|
109
|
14
|
100
|
|
|
|
29
|
if ($number < 0) {
|
110
|
2
|
|
|
|
|
3
|
$prefix = 'moins';
|
111
|
2
|
|
|
|
|
4
|
$number = -$number;
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
14
|
|
|
|
|
21
|
my $place = 0;
|
115
|
14
|
|
|
|
|
21
|
my $result = '';
|
116
|
14
|
|
|
|
|
17
|
my $plural_possible = 1;
|
117
|
14
|
|
|
|
|
16
|
my $plural_form = 0;
|
118
|
14
|
|
|
|
|
32
|
while ($number > 0) {
|
119
|
1530
|
|
|
|
|
1793
|
my $n = ($number % 1000);
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# par tranche de 1000
|
122
|
1530
|
100
|
|
|
|
2701
|
if ($n != 0) {
|
123
|
19
|
|
|
|
|
35
|
my $s = _num2words_less_1000($n);
|
124
|
19
|
100
|
100
|
|
|
83
|
if (($s =~ /\s*un\s*/) and ($place == 1)) {
|
125
|
|
|
|
|
|
|
# on donne pas le un pour mille
|
126
|
1
|
|
|
|
|
3
|
$result = $major[$place].$result;
|
127
|
|
|
|
|
|
|
} else {
|
128
|
18
|
100
|
|
|
|
41
|
if ($place == 0) {
|
129
|
13
|
100
|
100
|
|
|
66
|
if (($s =~ /cent\s*$/) and ($s !~ /^\s*cent/)) {
|
130
|
|
|
|
|
|
|
# nnn200 ... nnn900 avec "s"
|
131
|
1
|
|
|
|
|
3
|
$plural_form = 1;
|
132
|
|
|
|
|
|
|
} else {
|
133
|
|
|
|
|
|
|
# pas de "s" jamais
|
134
|
12
|
|
|
|
|
20
|
$plural_possible = 0;
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
18
|
100
|
100
|
|
|
57
|
if (($place > 0) and ($plural_possible)) {
|
139
|
1
|
50
|
|
|
|
5
|
if ($s !~ /^\s*un/) {
|
140
|
|
|
|
|
|
|
# avec "s"
|
141
|
1
|
|
|
|
|
2
|
$plural_form = 1;
|
142
|
|
|
|
|
|
|
} else {
|
143
|
|
|
|
|
|
|
# jamais de "s"
|
144
|
0
|
|
|
|
|
0
|
$plural_possible = 0;
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
|
148
|
18
|
|
|
|
|
45
|
$result = $s.$major[$place].$result;
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
}
|
151
|
|
|
|
|
|
|
|
152
|
1530
|
|
|
|
|
1650
|
$place++;
|
153
|
1530
|
|
|
|
|
3086
|
$number /= 1000;
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
14
|
|
|
|
|
46
|
$result = _trim($prefix.$result);
|
157
|
|
|
|
|
|
|
|
158
|
14
|
100
|
|
|
|
70
|
return $plural_form ? $result.'s' : $result;
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _trim {
|
162
|
14
|
|
|
14
|
|
37
|
my ($string) = @_;
|
163
|
|
|
|
|
|
|
|
164
|
14
|
|
|
|
|
53
|
$string =~ s/^\s+//;
|
165
|
14
|
|
|
|
|
47
|
$string =~ s/\s+$//;
|
166
|
|
|
|
|
|
|
|
167
|
14
|
|
|
|
|
34
|
return $string;
|
168
|
|
|
|
|
|
|
}
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1;
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__
|