line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Nums2Words; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
111567
|
use 5.006; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
178
|
|
4
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
177
|
|
5
|
4
|
|
|
4
|
|
66
|
use warnings; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
7765
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
12
|
|
|
|
|
|
|
'all' => [ |
13
|
|
|
|
|
|
|
qw( |
14
|
|
|
|
|
|
|
num2word |
15
|
|
|
|
|
|
|
) |
16
|
|
|
|
|
|
|
] |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT = qw( |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Lingua::PT::Nums2Words - Converts numbers to Portuguese words |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Lingua::PT::Nums2Words qw/num2word/; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$result = num2word(5); |
35
|
|
|
|
|
|
|
# $result now holds 'cinco' |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
@results = num2word(1,2,10,100,1000,9999); |
38
|
|
|
|
|
|
|
# @results now holds ('um', 'dois', 'dez', 'cem', 'mil', |
39
|
|
|
|
|
|
|
# 'nove mil novecentos e noventa e nove') |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Nums2Words converts numbers to Portuguese words (works with numbers |
44
|
|
|
|
|
|
|
ranging from 0 to 999.999.999.999.999). |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Does not support negative numbers. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 num2word |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This is the only function in this module. It turns numbers into words. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$number = num2word(77); |
53
|
|
|
|
|
|
|
# $number now holds "setenta e sete" |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub num2word { |
58
|
756
|
100
|
|
756
|
1
|
8309
|
@_ || return (); |
59
|
754
|
100
|
|
|
|
2309
|
my @numbers = wantarray ? @_ : shift; |
60
|
1764
|
50
|
|
|
|
4622
|
my @results = map { |
61
|
754
|
|
|
|
|
1055
|
$_ < 0 && return $_; |
62
|
|
|
|
|
|
|
#$_ > 999999999999999999 && return $_; |
63
|
1764
|
100
|
|
|
|
3414
|
$_ > 999999999999999 && return $_; |
64
|
1710
|
100
|
|
|
|
4582
|
if ( $_ > 999999999999 ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
65
|
27
|
|
|
|
|
298
|
my ($bil,$mil) = /(.*)(\d{12})$/; |
66
|
27
|
|
|
|
|
67
|
my $a = num2word($bil); |
67
|
27
|
|
|
|
|
64
|
my $b = num2word($mil); |
68
|
27
|
|
|
|
|
45
|
my $e = ""; |
69
|
27
|
100
|
100
|
|
|
152
|
if ($b && $mil =~ /^0{9}/) { |
70
|
3
|
|
|
|
|
8
|
$e = " e"; |
71
|
|
|
|
|
|
|
} |
72
|
27
|
100
|
|
|
|
56
|
my $s = $b ? ' ' : ''; |
73
|
27
|
100
|
|
|
|
276
|
return $a . ($bil == 1 ? ' bilião' : ' biliões') . $e . $s . $b; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ( $_ > 999999 ) { |
76
|
79
|
|
|
|
|
495
|
my ($mil,$uni) = /(.*)(\d{6})$/; |
77
|
79
|
|
|
|
|
154
|
my $a = num2word($mil); |
78
|
79
|
|
|
|
|
146
|
my $b = num2word($uni); |
79
|
79
|
|
|
|
|
101
|
my $e = ""; |
80
|
79
|
100
|
|
|
|
440
|
my $s = $b ? ' ' : ''; |
81
|
79
|
100
|
|
|
|
450
|
if ($uni =~ /^000\d{0,2}[1-9]\d{0,2}|0\d?[1-9]\d?000|[1-9]0{5}/) { |
82
|
13
|
|
|
|
|
22
|
$e = " e"; |
83
|
|
|
|
|
|
|
} |
84
|
79
|
100
|
|
|
|
541
|
return $a . ($mil == 1 ? ' milhão' : ' milhões') . $e . $s . $b; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ( $_ > 9999 ) { |
87
|
138
|
|
|
|
|
597
|
/\d\d\d$/; |
88
|
138
|
|
|
|
|
272
|
my $a = num2word($`); |
89
|
138
|
|
|
|
|
443
|
my $b = num2word( 1000 + $& ); |
90
|
138
|
|
|
|
|
706
|
return "$a $b"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
1466
|
|
|
|
|
2736
|
s!^00+!!; |
94
|
1466
|
|
|
|
|
2045
|
s!^0+(?=[1-9])!!; |
95
|
1466
|
|
|
|
|
2180
|
s!9(?=\d\d\d)!nove mil e !; |
96
|
1466
|
|
|
|
|
1916
|
s!8(?=\d\d\d)!oito mil e !; |
97
|
1466
|
|
|
|
|
1866
|
s!7(?=\d\d\d)!sete mil e !; |
98
|
1466
|
|
|
|
|
2229
|
s!6(?=\d\d\d)!seis mil e !; |
99
|
1466
|
|
|
|
|
1916
|
s!5(?=\d\d\d)!cinco mil e !; |
100
|
1466
|
|
|
|
|
2427
|
s!4(?=\d\d\d)!quatro mil e !; |
101
|
1466
|
|
|
|
|
1872
|
s!3(?=\d\d\d)!três mil e !; |
102
|
1466
|
|
|
|
|
1818
|
s!2(?=\d\d\d)!dois mil e !; |
103
|
1466
|
|
|
|
|
2278
|
s!1(?=\d\d\d)!mil e !; |
104
|
1466
|
|
|
|
|
2236
|
s!9(?=\d\d)!novecentos e !; |
105
|
1466
|
|
|
|
|
2464
|
s!8(?=\d\d)!oitocentos e !; |
106
|
1466
|
|
|
|
|
2102
|
s!7(?=\d\d)!setecentos e !; |
107
|
1466
|
|
|
|
|
2501
|
s!6(?=\d\d)!seiscentos e !; |
108
|
1466
|
|
|
|
|
2446
|
s!5(?=\d\d)!quinhentos e !; |
109
|
1466
|
|
|
|
|
2047
|
s!4(?=\d\d)!quatrocentos e !; |
110
|
1466
|
|
|
|
|
2243
|
s!3(?=\d\d)!trezentos e !; |
111
|
1466
|
|
|
|
|
2500
|
s!2(?=\d\d)!duzentos e !; |
112
|
1466
|
|
|
|
|
1804
|
s!100!cem!; |
113
|
1466
|
|
|
|
|
1813
|
s!mil e 0+(?=[1-9])!mil e !; |
114
|
1466
|
|
|
|
|
1948
|
s!1(?=\d\d)!cento e !; |
115
|
1466
|
|
|
|
|
2039
|
s!9(?=\d)!noventa e !; |
116
|
1466
|
|
|
|
|
2762
|
s!8(?=\d)!oitenta e !; |
117
|
1466
|
|
|
|
|
2418
|
s!7(?=\d)!setenta e !; |
118
|
1466
|
|
|
|
|
1980
|
s!6(?=\d)!sessenta e !; |
119
|
1466
|
|
|
|
|
1969
|
s!5(?=\d)!cinquenta e !; |
120
|
1466
|
|
|
|
|
3377
|
s!4(?=\d)!quarenta e !; |
121
|
1466
|
|
|
|
|
2346
|
s!3(?=\d)!trinta e !; |
122
|
1466
|
|
|
|
|
2203
|
s!2(?=\d)!vinte e !; |
123
|
1466
|
|
|
|
|
2467
|
s/ e 0+(?=[1-9])/ e /; |
124
|
1466
|
|
|
|
|
2635
|
s/ e 0+//; |
125
|
1466
|
|
|
|
|
2026
|
s/19/dezanove/; |
126
|
1466
|
|
|
|
|
2042
|
s/18/dezoito/; |
127
|
1466
|
|
|
|
|
1676
|
s/17/dezassete/; |
128
|
1466
|
|
|
|
|
1749
|
s/16/dezasseis/; |
129
|
1466
|
|
|
|
|
1820
|
s/15/quinze/; |
130
|
1466
|
|
|
|
|
1920
|
s/14/catorze/; |
131
|
1466
|
|
|
|
|
1710
|
s/13/treze/; |
132
|
1466
|
|
|
|
|
1923
|
s/12/doze/; |
133
|
1466
|
|
|
|
|
2261
|
s/11/onze/; |
134
|
1466
|
|
|
|
|
2128
|
s/10/dez/; |
135
|
1466
|
|
|
|
|
2237
|
s/9/nove/; |
136
|
1466
|
|
|
|
|
2236
|
s/8/oito/; |
137
|
1466
|
|
|
|
|
2653
|
s/7/sete/; |
138
|
1466
|
|
|
|
|
1786
|
s/6/seis/; |
139
|
1466
|
|
|
|
|
2125
|
s/5/cinco/; |
140
|
1466
|
|
|
|
|
2027
|
s/4/quatro/; |
141
|
1466
|
|
|
|
|
2688
|
s/3/três/; |
142
|
1466
|
|
|
|
|
2394
|
s/2/dois/; |
143
|
1466
|
|
|
|
|
2006
|
s/1/um/; |
144
|
1466
|
|
|
|
|
1913
|
s/0/zero/; |
145
|
|
|
|
|
|
|
|
146
|
1466
|
|
|
|
|
2450
|
s!mil e (novecentos|oitocentos|setecentos|seiscentos) e!mil $1 e!; |
147
|
1466
|
|
|
|
|
2100
|
s!mil e (quinhentos|quatrocentos|trezentos|duzentos) e!mil $1 e!; |
148
|
1466
|
|
|
|
|
1948
|
s!mil e cento!mil cento!; |
149
|
|
|
|
|
|
|
|
150
|
1466
|
|
|
|
|
3593
|
$_; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} @numbers; |
153
|
|
|
|
|
|
|
|
154
|
456
|
100
|
|
|
|
3122
|
return wantarray ? @results : $results[0]; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
__END__ |