line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding coding:iso-8859-1 -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Started by Vitor Serra Mori at 2004-05-19 |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# PPCG: 0.7 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Lingua::SV::Num2Word; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
124432
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
8
|
use Exporter (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
13
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION @ISA @EXPORT_OK); |
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
136
|
|
14
|
1
|
|
|
1
|
|
3
|
$VERSION = '0.05'; |
15
|
1
|
|
|
|
|
23
|
@ISA = qw(Exporter); |
16
|
1
|
|
|
|
|
786
|
@EXPORT_OK = qw(&num2sv_cardinal); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# {{{ num2sv_cardinal convert number to text |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
sub num2sv_cardinal { |
22
|
36
|
50
|
|
36
|
1
|
2230
|
my $positive = ($_[0]>=0) ? shift : return; |
23
|
36
|
|
|
|
|
28
|
my $out; |
24
|
36
|
|
|
|
|
98
|
my @tokens1 = qw(noll ett två tre fyra fem sex sju åtta nio tio elva |
25
|
|
|
|
|
|
|
tolv tretton fjorton femton sexton sjutton arton nitton); # 0-19 Cardinals |
26
|
36
|
|
|
|
|
65
|
my @tokens2 = qw(tjugo trettio fyrtio femtio sextio sjutio åttio nittio); # 20-90 Cardinals (end with zero) |
27
|
|
|
|
|
|
|
|
28
|
36
|
100
|
|
|
|
65
|
return $tokens1[$positive] if($positive < 20); # interval 0 - 19 |
29
|
|
|
|
|
|
|
|
30
|
30
|
100
|
|
|
|
67
|
if($positive < 100) { # interval 20 - 99 |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
31
|
3
|
|
|
|
|
7
|
my @num = split '',$positive; |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
6
|
$out = $tokens2[$num[0]-2]; |
34
|
3
|
50
|
|
|
|
9
|
$out .= $tokens1[$num[1]] if ($num[1]); |
35
|
|
|
|
|
|
|
} elsif($positive < 1000) { # interval 100 - 999 |
36
|
14
|
|
|
|
|
25
|
my @num = split '',$positive; |
37
|
|
|
|
|
|
|
|
38
|
14
|
|
|
|
|
23
|
$out = $tokens1[$num[0]].'hundra'; |
39
|
|
|
|
|
|
|
|
40
|
14
|
100
|
100
|
|
|
40
|
if ((int $num[1].$num[2]) < 20 && (int $num[1].$num[2])>0 ) { |
41
|
1
|
|
|
|
|
3
|
$out .= &num2sv_cardinal(int $num[1].$num[2]); |
42
|
|
|
|
|
|
|
} else { |
43
|
13
|
100
|
|
|
|
26
|
$out .= $tokens2[$num[1]-2] if($num[1]); |
44
|
13
|
100
|
|
|
|
31
|
$out .= $tokens1[$num[2]] if($num[2]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} elsif($positive < 1000_000) { # interval 1000 - 999_999 |
47
|
9
|
|
|
|
|
23
|
my @num = split '',$positive; |
48
|
9
|
|
|
|
|
17
|
my @sub = splice @num,-3; |
49
|
|
|
|
|
|
|
|
50
|
9
|
|
|
|
|
28
|
$out = &num2sv_cardinal(int join '',@num); |
51
|
9
|
|
|
|
|
10
|
$out .= 'tusen'; |
52
|
9
|
100
|
|
|
|
99
|
$out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0); |
53
|
|
|
|
|
|
|
} elsif($positive < 1_000_000_000) { # interval 1_000_000 - 999_999_999 |
54
|
3
|
|
|
|
|
10
|
my @num = split '',$positive; |
55
|
3
|
|
|
|
|
7
|
my @sub = splice @num,-6; |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
9
|
$out = &num2sv_cardinal(int join '',@num); |
58
|
3
|
|
|
|
|
7
|
$out .= ' miljoner '; |
59
|
3
|
50
|
|
|
|
11
|
$out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
30
|
|
|
|
|
101
|
return $out; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# }}} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |