line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::NOR::Num2Word; |
4
|
|
|
|
|
|
|
# ABSTRACT: Number 2 word conversion in NOR. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
724
|
use 5.10.1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
11
|
1
|
|
|
1
|
|
12
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
574
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# }}} |
14
|
|
|
|
|
|
|
# {{{ variables declaration |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %group1 = qw( 0 null 1 en 2 to |
21
|
|
|
|
|
|
|
3 tre 4 fire 5 fem |
22
|
|
|
|
|
|
|
6 seks 7 sju 8 åtte |
23
|
|
|
|
|
|
|
9 ni 10 ti 11 ellve |
24
|
|
|
|
|
|
|
12 tolv 13 tretten 14 fjorten |
25
|
|
|
|
|
|
|
15 femten 16 seksten 17 sytten |
26
|
|
|
|
|
|
|
18 atten 19 nitten |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
my %group2 = qw( 20 tjue 30 tretti 40 førti |
29
|
|
|
|
|
|
|
50 femti 60 seksti 70 sytti |
30
|
|
|
|
|
|
|
80 åtti 90 nitti |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
my %group3 = ( 100, 'ett hundre', 200, 'to hundre', 300, 'tre hundre', |
33
|
|
|
|
|
|
|
400, 'fire hundre', 500, 'fem hundre', 600, 'seks hundre', |
34
|
|
|
|
|
|
|
700, 'sju hundre', 800, 'åtte hundre', 900, 'ni hundre' |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $singleton; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# }}} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# {{{ new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new |
44
|
|
|
|
|
|
|
{ |
45
|
2
|
|
|
2
|
1
|
1094
|
my $invocant = shift; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
33
|
|
|
9
|
my $class = ref ( $invocant ) || $invocant; |
48
|
2
|
|
100
|
|
|
10
|
$singleton ||= bless {}, $class; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
5
|
return $singleton; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# }}} |
54
|
|
|
|
|
|
|
# {{{ num2no_cardinal |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub num2no_cardinal |
57
|
|
|
|
|
|
|
{ |
58
|
53
|
|
|
53
|
1
|
285
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
53
|
|
|
|
|
53
|
my $result = ''; |
61
|
53
|
|
100
|
|
|
91
|
my $number = shift // return $result; |
62
|
|
|
|
|
|
|
#print "$number -> "; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# check if number has decimals > 0, allowing whole numbers written as 2.00 |
65
|
52
|
|
|
|
|
72
|
$number =~ /(\d+)\.(\d+)/; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# numbers less than 0 are not supported and numbers containg decimals greater than 0 |
68
|
52
|
100
|
66
|
|
|
180
|
return $result if ( $number < 0 || ( defined $2 && $2 > 0 ) ); |
|
|
|
66
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
50
|
|
|
|
|
49
|
my $reminder = 0; |
71
|
|
|
|
|
|
|
|
72
|
50
|
100
|
|
|
|
115
|
if ( $number < 20 ) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
19
|
|
|
|
|
28
|
$result = $group1{$number}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
elsif ( $number < 100 ) |
78
|
|
|
|
|
|
|
{ |
79
|
9
|
|
|
|
|
10
|
$reminder = $number % 10; |
80
|
9
|
100
|
|
|
|
14
|
if ( $reminder == 0 ) |
81
|
|
|
|
|
|
|
{ |
82
|
1
|
|
|
|
|
9
|
$result = $group2{$number}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else |
85
|
|
|
|
|
|
|
{ |
86
|
8
|
|
|
|
|
31
|
$result = $group2{$number - $reminder} . ' ' . $self->num2no_cardinal( $reminder ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
elsif ($number < 1000) |
91
|
|
|
|
|
|
|
{ |
92
|
9
|
|
|
|
|
11
|
$reminder = $number % 100; |
93
|
9
|
100
|
|
|
|
13
|
if ( $reminder == 0 ) |
94
|
|
|
|
|
|
|
{ |
95
|
2
|
|
|
|
|
4
|
$result = $group3{$number}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
7
|
|
|
|
|
19
|
$result = $group3{$number - $reminder} . ' og ' . $self->num2no_cardinal( $reminder ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
elsif ( $number < 1000000 ) |
104
|
|
|
|
|
|
|
{ |
105
|
8
|
|
|
|
|
7
|
$reminder = $number % 1000; |
106
|
|
|
|
|
|
|
|
107
|
8
|
100
|
|
|
|
129
|
my $tmp1 = ( $reminder != 0 ) ? ' '.$self->num2no_cardinal($reminder) : ''; |
108
|
8
|
|
|
|
|
14
|
my $tmp2 = substr( $number, 0, length( $number ) - 3 ); |
109
|
8
|
|
|
|
|
14
|
my $tmp3 = $tmp2 % 10; |
110
|
|
|
|
|
|
|
|
111
|
8
|
|
|
|
|
8
|
my $space = ''; |
112
|
8
|
100
|
100
|
|
|
30
|
$space = ' og' if ( $reminder < 100 && $reminder != 0 ); |
113
|
|
|
|
|
|
|
|
114
|
8
|
100
|
66
|
|
|
23
|
if ( $tmp3 == 1 && $tmp2 == 1 ) |
115
|
|
|
|
|
|
|
{ |
116
|
1
|
|
|
|
|
2
|
$tmp2 = 'ett tusen'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else |
119
|
|
|
|
|
|
|
{ |
120
|
7
|
|
|
|
|
15
|
$tmp2 = $self->num2no_cardinal($tmp2) . ' tusen'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
8
|
|
|
|
|
14
|
$result = $tmp2 . $space . $tmp1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
elsif ( $number < 1000000000 ) |
127
|
|
|
|
|
|
|
{ |
128
|
4
|
|
|
|
|
5
|
$reminder = $number % 1000000; |
129
|
|
|
|
|
|
|
|
130
|
4
|
100
|
|
|
|
8
|
my $tmp1 = ( $reminder != 0 ) ? ' ' . $self->num2no_cardinal($reminder) : ''; |
131
|
4
|
|
|
|
|
8
|
my $tmp2 = substr( $number, 0, length( $number ) - 6 ); |
132
|
4
|
|
|
|
|
5
|
my $tmp3 = $tmp2 % 10; |
133
|
|
|
|
|
|
|
|
134
|
4
|
|
|
|
|
5
|
my $space = ''; |
135
|
4
|
100
|
100
|
|
|
22
|
$space = ' og' if ( $reminder < 100000 && $reminder != 0 ); |
136
|
|
|
|
|
|
|
|
137
|
4
|
100
|
66
|
|
|
13
|
if ( $tmp3 == 1 && $tmp2 == 1 ) |
138
|
|
|
|
|
|
|
{ |
139
|
1
|
|
|
|
|
17
|
$tmp2 = 'en million'; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else |
142
|
|
|
|
|
|
|
{ |
143
|
3
|
|
|
|
|
6
|
$tmp2 = $self->num2no_cardinal( $tmp2 ) . ' millioner'; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
4
|
|
|
|
|
9
|
$result = $tmp2 . $space . $tmp1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else |
150
|
|
|
|
|
|
|
{ |
151
|
|
|
|
|
|
|
# >= 1 000 000 000 unsupported |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
50
|
|
|
|
|
1203
|
return $result; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# }}} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__END__ |