line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Nums2Words;
|
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
195399
|
use 5.006;
|
|
4
|
|
|
|
|
28
|
|
4
|
4
|
|
|
4
|
|
21
|
use strict;
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
98
|
|
5
|
4
|
|
|
4
|
|
19
|
use warnings;
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
4616
|
|
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.07';
|
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
|
7242
|
@_ || return ();
|
59
|
754
|
100
|
|
|
|
2051
|
my @numbers = wantarray ? @_ : shift;
|
60
|
|
|
|
|
|
|
my @results = map {
|
61
|
754
|
50
|
|
|
|
1067
|
$_ < 0 && return $_;
|
|
1764
|
|
|
|
|
3349
|
|
62
|
|
|
|
|
|
|
#$_ > 999999999999999999 && return $_;
|
63
|
1764
|
100
|
|
|
|
3079
|
$_ > 999999999999999 && return $_;
|
64
|
1710
|
100
|
|
|
|
3479
|
if ( $_ > 999999999999 ) {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
65
|
27
|
|
|
|
|
193
|
my ($bil,$mil) = /(.*)(\d{12})$/;
|
66
|
27
|
|
|
|
|
56
|
my $a = num2word($bil);
|
67
|
27
|
|
|
|
|
50
|
my $b = num2word($mil);
|
68
|
27
|
|
|
|
|
33
|
my $e = "";
|
69
|
27
|
100
|
100
|
|
|
107
|
if ($b && $mil =~ /^0{9}/) {
|
70
|
3
|
|
|
|
|
5
|
$e = " e";
|
71
|
|
|
|
|
|
|
}
|
72
|
27
|
100
|
|
|
|
45
|
my $s = $b ? ' ' : '';
|
73
|
27
|
100
|
|
|
|
169
|
return $a . ($bil == 1 ? ' bilião' : ' biliões') . $e . $s . $b;
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
elsif ( $_ > 999999 ) {
|
76
|
79
|
|
|
|
|
482
|
my ($mil,$uni) = /(.*)(\d{6})$/;
|
77
|
79
|
|
|
|
|
165
|
my $a = num2word($mil);
|
78
|
79
|
|
|
|
|
397
|
my $b = num2word($uni);
|
79
|
79
|
|
|
|
|
116
|
my $e = "";
|
80
|
79
|
100
|
|
|
|
125
|
my $s = $b ? ' ' : '';
|
81
|
79
|
100
|
|
|
|
332
|
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
|
|
|
|
576
|
return $a . ($mil == 1 ? ' milhão' : ' milhões') . $e . $s . $b;
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
elsif ( $_ > 9999 ) {
|
87
|
138
|
|
|
|
|
401
|
/\d\d\d$/;
|
88
|
138
|
|
|
|
|
256
|
my $a = num2word($`);
|
89
|
138
|
|
|
|
|
377
|
my $b = num2word( 1000 + $& );
|
90
|
138
|
|
|
|
|
944
|
return "$a $b";
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
else {
|
93
|
1466
|
|
|
|
|
2066
|
s!^00+!!;
|
94
|
1466
|
|
|
|
|
1754
|
s!^0+(?=[1-9])!!;
|
95
|
1466
|
|
|
|
|
1841
|
s!9(?=\d\d\d)!nove mil e !;
|
96
|
1466
|
|
|
|
|
1797
|
s!8(?=\d\d\d)!oito mil e !;
|
97
|
1466
|
|
|
|
|
2398
|
s!7(?=\d\d\d)!sete mil e !;
|
98
|
1466
|
|
|
|
|
1803
|
s!6(?=\d\d\d)!seis mil e !;
|
99
|
1466
|
|
|
|
|
1732
|
s!5(?=\d\d\d)!cinco mil e !;
|
100
|
1466
|
|
|
|
|
2200
|
s!4(?=\d\d\d)!quatro mil e !;
|
101
|
1466
|
|
|
|
|
1828
|
s!3(?=\d\d\d)!três mil e !;
|
102
|
1466
|
|
|
|
|
1797
|
s!2(?=\d\d\d)!dois mil e !;
|
103
|
1466
|
|
|
|
|
2008
|
s!1(?=\d\d\d)!mil e !;
|
104
|
1466
|
|
|
|
|
1832
|
s!9(?=\d\d)!novecentos e !;
|
105
|
1466
|
|
|
|
|
1907
|
s!8(?=\d\d)!oitocentos e !;
|
106
|
1466
|
|
|
|
|
1852
|
s!7(?=\d\d)!setecentos e !;
|
107
|
1466
|
|
|
|
|
1843
|
s!6(?=\d\d)!seiscentos e !;
|
108
|
1466
|
|
|
|
|
1887
|
s!5(?=\d\d)!quinhentos e !;
|
109
|
1466
|
|
|
|
|
1834
|
s!4(?=\d\d)!quatrocentos e !;
|
110
|
1466
|
|
|
|
|
1843
|
s!3(?=\d\d)!trezentos e !;
|
111
|
1466
|
|
|
|
|
1917
|
s!2(?=\d\d)!duzentos e !;
|
112
|
1466
|
|
|
|
|
2015
|
s!100!cem!;
|
113
|
1466
|
|
|
|
|
2646
|
s!mil e 0+(?=[1-9])!mil e !;
|
114
|
1466
|
|
|
|
|
1853
|
s!1(?=\d\d)!cento e !;
|
115
|
1466
|
|
|
|
|
1821
|
s!9(?=\d)!noventa e !;
|
116
|
1466
|
|
|
|
|
1797
|
s!8(?=\d)!oitenta e !;
|
117
|
1466
|
|
|
|
|
1780
|
s!7(?=\d)!setenta e !;
|
118
|
1466
|
|
|
|
|
1748
|
s!6(?=\d)!sessenta e !;
|
119
|
1466
|
|
|
|
|
2205
|
s!5(?=\d)!cinquenta e !;
|
120
|
1466
|
|
|
|
|
1943
|
s!4(?=\d)!quarenta e !;
|
121
|
1466
|
|
|
|
|
1847
|
s!3(?=\d)!trinta e !;
|
122
|
1466
|
|
|
|
|
1801
|
s!2(?=\d)!vinte e !;
|
123
|
1466
|
|
|
|
|
2033
|
s/ e 0+(?=[1-9])/ e /;
|
124
|
1466
|
|
|
|
|
2209
|
s/ e 0+//;
|
125
|
1466
|
|
|
|
|
1757
|
s/19/dezanove/;
|
126
|
1466
|
|
|
|
|
1668
|
s/18/dezoito/;
|
127
|
1466
|
|
|
|
|
1628
|
s/17/dezassete/;
|
128
|
1466
|
|
|
|
|
8411
|
s/16/dezasseis/;
|
129
|
1466
|
|
|
|
|
1652
|
s/15/quinze/;
|
130
|
1466
|
|
|
|
|
1600
|
s/14/catorze/;
|
131
|
1466
|
|
|
|
|
1642
|
s/13/treze/;
|
132
|
1466
|
|
|
|
|
1765
|
s/12/doze/;
|
133
|
1466
|
|
|
|
|
1749
|
s/11/onze/;
|
134
|
1466
|
|
|
|
|
1649
|
s/10/dez/;
|
135
|
1466
|
|
|
|
|
1752
|
s/9/nove/;
|
136
|
1466
|
|
|
|
|
1729
|
s/8/oito/;
|
137
|
1466
|
|
|
|
|
1728
|
s/7/sete/;
|
138
|
1466
|
|
|
|
|
10614
|
s/6/seis/;
|
139
|
1466
|
|
|
|
|
1717
|
s/5/cinco/;
|
140
|
1466
|
|
|
|
|
1833
|
s/4/quatro/;
|
141
|
1466
|
|
|
|
|
1804
|
s/3/três/;
|
142
|
1466
|
|
|
|
|
2152
|
s/2/dois/;
|
143
|
1466
|
|
|
|
|
2092
|
s/1/um/;
|
144
|
1466
|
|
|
|
|
1573
|
s/0/zero/;
|
145
|
|
|
|
|
|
|
|
146
|
1466
|
|
|
|
|
1894
|
s!mil e (novecentos|oitocentos|setecentos|seiscentos) e!mil $1 e!;
|
147
|
1466
|
|
|
|
|
1892
|
s!mil e (quinhentos|quatrocentos|trezentos|duzentos) e!mil $1 e!;
|
148
|
1466
|
|
|
|
|
1741
|
s!mil e cento!mil cento!;
|
149
|
|
|
|
|
|
|
|
150
|
1466
|
|
|
|
|
3133
|
$_;
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
} @numbers;
|
153
|
|
|
|
|
|
|
|
154
|
456
|
100
|
|
|
|
1618
|
return wantarray ? @results : $results[0];
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1;
|
158
|
|
|
|
|
|
|
__END__
|