| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::NLD::Num2Word; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Number 2 word conversion in NLD. |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
136978
|
use 5.16.0; |
|
|
1
|
|
|
|
|
5
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use utf8; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
33
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
100
|
|
|
12
|
1
|
|
|
1
|
|
790
|
use Readonly; |
|
|
1
|
|
|
|
|
5378
|
|
|
|
1
|
|
|
|
|
86
|
|
|
13
|
1
|
|
|
1
|
|
700
|
use Export::Attrs; |
|
|
1
|
|
|
|
|
14828
|
|
|
|
1
|
|
|
|
|
8
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# }}} |
|
16
|
|
|
|
|
|
|
# {{{ var block |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2015-present'; |
|
19
|
|
|
|
|
|
|
our $VERSION = '0.2603230'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# }}} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# {{{ num2nld_cardinal convert number to text |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub num2nld_cardinal :Export { |
|
26
|
7
|
|
|
7
|
1
|
230358
|
my $positive = shift; |
|
27
|
|
|
|
|
|
|
|
|
28
|
7
|
50
|
33
|
|
|
85
|
croak 'You should specify a number from interval [0, 999_999_999]' |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if !defined $positive |
|
30
|
|
|
|
|
|
|
|| $positive !~ m{\A\d+\z}xms |
|
31
|
|
|
|
|
|
|
|| $positive < 0 |
|
32
|
|
|
|
|
|
|
|| $positive > 999_999_999; |
|
33
|
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
61
|
my @tokens1 = qw(nul een twee drie vier vijf zes zeven acht negen tien |
|
35
|
|
|
|
|
|
|
elf twaalf dertien veertien vijftien zestien zeventien achtien negentien); |
|
36
|
7
|
|
|
|
|
26
|
my @tokens2 = qw(twintig dertig veertig vijftig zestig zeventig tachtig negentig honderd); |
|
37
|
|
|
|
|
|
|
|
|
38
|
7
|
50
|
33
|
|
|
31
|
return $tokens1[$positive] if ($positive >= 0 && $positive < 20); # 0 .. 19 |
|
39
|
|
|
|
|
|
|
|
|
40
|
7
|
|
|
|
|
17
|
my $out; # string for return value construction |
|
41
|
|
|
|
|
|
|
my $one_idx; # index for tokens1 array |
|
42
|
7
|
|
|
|
|
0
|
my $remain; # remainder |
|
43
|
|
|
|
|
|
|
|
|
44
|
7
|
100
|
66
|
|
|
45
|
if ($positive > 19 && $positive < 101) { # 20 .. 100 |
|
|
|
100
|
66
|
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
45
|
3
|
|
|
|
|
8
|
$one_idx = int ($positive / 10); |
|
46
|
3
|
|
|
|
|
6
|
$remain = $positive % 10; |
|
47
|
|
|
|
|
|
|
|
|
48
|
3
|
50
|
|
|
|
10
|
$out = "$tokens1[$remain]en" if ($remain); |
|
49
|
3
|
|
|
|
|
8
|
$out .= $tokens2[$one_idx - 2]; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
elsif ($positive > 100 && $positive < 1000) { # 101 .. 999 |
|
52
|
3
|
|
|
|
|
10
|
$one_idx = int ($positive / 100); |
|
53
|
3
|
|
|
|
|
6
|
$remain = $positive % 100; |
|
54
|
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
8
|
$out = "$tokens1[$one_idx]honderd"; |
|
56
|
3
|
50
|
|
|
|
50
|
$out .= $remain ? num2nld_cardinal($remain) : ''; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999 |
|
59
|
1
|
|
|
|
|
4
|
$one_idx = int ($positive / 1000); |
|
60
|
1
|
|
|
|
|
4
|
$remain = $positive % 1000; |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
3
|
$out = num2nld_cardinal($one_idx) . 'duizend '; |
|
63
|
1
|
50
|
|
|
|
15
|
$out .= $remain ? num2nld_cardinal($remain) : ''; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
elsif ( $positive > 999_999 |
|
66
|
|
|
|
|
|
|
&& $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999 |
|
67
|
0
|
|
|
|
|
0
|
$one_idx = int ($positive / 1000000); |
|
68
|
0
|
|
|
|
|
0
|
$remain = $positive % 1000000; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
$out = num2nld_cardinal($one_idx) . " miljoen"; |
|
71
|
0
|
0
|
|
|
|
0
|
$out .= $remain ? ' ' . num2nld_cardinal($remain) : ''; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
7
|
|
|
|
|
36
|
return $out; |
|
75
|
1
|
|
|
1
|
|
621
|
} |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
8
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# }}} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |