line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:iso-8859-2; -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# (c) 2002-2004 PetaMem, s.r.o. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# PPCG: 0.7 |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Lingua::CS::Num2Word; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# {{{ use block |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
12125
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# }}} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# {{{ BEGIN |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
1
|
|
|
1
|
|
9
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
20
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $REVISION @ISA @EXPORT_OK); |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
172
|
|
21
|
1
|
|
|
1
|
|
3
|
$VERSION = 0.03; |
22
|
1
|
|
|
|
|
6
|
($REVISION) = '$Revision: 1.14 $' =~ /([\d.]+)/; |
23
|
1
|
|
|
|
|
19
|
@ISA = qw(Exporter); |
24
|
1
|
|
|
|
|
1208
|
@EXPORT_OK = qw(&num2cs_cardinal); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# }}} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# {{{ variables |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %token1 = qw( 0 nula 1 jedna 2 dva |
32
|
|
|
|
|
|
|
3 tři 4 čtyři 5 pět |
33
|
|
|
|
|
|
|
6 šest 7 sedm 8 osm |
34
|
|
|
|
|
|
|
9 devět 10 deset 11 jedenáct |
35
|
|
|
|
|
|
|
12 dvanáct 13 třináct 14 čtrnáct |
36
|
|
|
|
|
|
|
15 patnáct 16 šestnáct 17 sedmnáct |
37
|
|
|
|
|
|
|
18 osmnáct 19 devatenáct |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
my %token2 = qw( 20 dvacet 30 třicet 40 čtyřicet |
40
|
|
|
|
|
|
|
50 padesát 60 šedesát 70 sedmdesát |
41
|
|
|
|
|
|
|
80 osmdesát 90 devadesát |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
my %token3 = ( 100, 'sto', 200, 'dvě stě', 300, 'tři sta', |
44
|
|
|
|
|
|
|
400, 'čtyři sta', 500, 'pět set', 600, 'šest set', |
45
|
|
|
|
|
|
|
700, 'sedm set', 800, 'osm set', 900, 'devět set' |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# }}} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# {{{ num2cs_cardinal number to string conversion |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub num2cs_cardinal { |
53
|
0
|
|
|
0
|
1
|
|
my $result = ''; |
54
|
0
|
0
|
|
|
|
|
my $number = defined $_[0] ? shift : return $result; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# numbers less than 0 are not supported yet |
57
|
0
|
0
|
|
|
|
|
return $result if $number < 0; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $reminder = 0; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if ($number < 20) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$result = $token1{$number}; |
63
|
|
|
|
|
|
|
} elsif ($number < 100) { |
64
|
0
|
|
|
|
|
|
$reminder = $number % 10; |
65
|
0
|
0
|
|
|
|
|
if ($reminder == 0) { |
66
|
0
|
|
|
|
|
|
$result = $token2{$number}; |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
|
$result = $token2{$number - $reminder}.' '.num2cs_cardinal($reminder); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} elsif ($number < 1_000) { |
71
|
0
|
|
|
|
|
|
$reminder = $number % 100; |
72
|
0
|
0
|
|
|
|
|
if ($reminder != 0) { |
73
|
0
|
|
|
|
|
|
$result = $token3{$number - $reminder}.' '.num2cs_cardinal($reminder); |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
$result = $token3{$number}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} elsif ($number < 1_000_000) { |
78
|
0
|
|
|
|
|
|
$reminder = $number % 1_000; |
79
|
0
|
0
|
|
|
|
|
my $tmp1 = ($reminder != 0) ? ' '.num2cs_cardinal($reminder) : ''; |
80
|
0
|
|
|
|
|
|
my $tmp2 = substr($number, 0, length($number)-3); |
81
|
0
|
|
|
|
|
|
my $tmp3 = $tmp2 % 100; |
82
|
0
|
|
|
|
|
|
my $tmp4 = $tmp2 % 10; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
|
if ($tmp3 < 9 || $tmp3 > 20) { |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
|
if ($tmp4 == 1 && $tmp2 == 1) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$tmp2 = 'tisíc'; |
88
|
|
|
|
|
|
|
} elsif ($tmp4 == 1) { |
89
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2 - $tmp4).' jeden tisíc'; |
90
|
|
|
|
|
|
|
} elsif($tmp4 > 1 && $tmp4 < 5) { |
91
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' tisíce'; |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' tisíc'; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' tisíc'; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$result = $tmp2.$tmp1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} elsif ($number < 1_000_000_000) { |
102
|
0
|
|
|
|
|
|
$reminder = $number % 1_000_000; |
103
|
0
|
0
|
|
|
|
|
my $tmp1 = ($reminder != 0) ? ' '.num2cs_cardinal($reminder) : ''; |
104
|
0
|
|
|
|
|
|
my $tmp2 = substr($number, 0, length($number)-6); |
105
|
0
|
|
|
|
|
|
my $tmp3 = $tmp2 % 100; |
106
|
0
|
|
|
|
|
|
my $tmp4 = $tmp2 % 10; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
0
|
|
|
|
if ($tmp3 < 9 || $tmp3 > 20) { |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
0
|
|
|
|
if ($tmp4 == 1 && $tmp2 == 1) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
$tmp2 = 'milion'; |
112
|
|
|
|
|
|
|
} elsif ($tmp4 == 1) { |
113
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2 - $tmp4).' jeden milion'; |
114
|
|
|
|
|
|
|
} elsif($tmp4 > 1 && $tmp4 < 5) { |
115
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' miliony'; |
116
|
|
|
|
|
|
|
} else { |
117
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' milionů'; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
|
$tmp2 = num2cs_cardinal($tmp2).' milionů'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$result = $tmp2.$tmp1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} else { |
126
|
|
|
|
|
|
|
# >= 1 000 000 000 unsupported yet (miliard) |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return $result; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# }}} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
__END__ |