line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8 -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# (c) 2002-2010 PetaMem, s.r.o. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Lingua::RUS::Number; |
7
|
|
|
|
|
|
|
# ABSTRACT: Number 2 word conversion in RUS. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# {{{ use block |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
26506
|
use 5.10.1; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
49
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
14
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
26
|
|
15
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
847
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
11814
|
|
|
1
|
|
|
|
|
8
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# }}} |
20
|
|
|
|
|
|
|
# {{{ variables declaration |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 0.136; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Preloaded methods go here. |
25
|
1
|
|
|
1
|
|
66
|
use vars qw(%diw %nom); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
904
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
%diw = ( |
28
|
|
|
|
|
|
|
0 => { |
29
|
|
|
|
|
|
|
0 => { 0 => "ноль", 1 => 1}, |
30
|
|
|
|
|
|
|
1 => { 0 => "", 1 => 2}, |
31
|
|
|
|
|
|
|
2 => { 0 => "", 1 => 3}, |
32
|
|
|
|
|
|
|
3 => { 0 => "три", 1 => 0}, |
33
|
|
|
|
|
|
|
4 => { 0 => "четыре", 1 => 0}, |
34
|
|
|
|
|
|
|
5 => { 0 => "пять", 1 => 1}, |
35
|
|
|
|
|
|
|
6 => { 0 => "шесть", 1 => 1}, |
36
|
|
|
|
|
|
|
7 => { 0 => "семь", 1 => 1}, |
37
|
|
|
|
|
|
|
8 => { 0 => "восемь", 1 => 1}, |
38
|
|
|
|
|
|
|
9 => { 0 => "девять", 1 => 1}, |
39
|
|
|
|
|
|
|
10 => { 0 => "десять", 1 => 1}, |
40
|
|
|
|
|
|
|
11 => { 0 => "одинадцать", 1 => 1}, |
41
|
|
|
|
|
|
|
12 => { 0 => "двенадцать", 1 => 1}, |
42
|
|
|
|
|
|
|
13 => { 0 => "тринадцать", 1 => 1}, |
43
|
|
|
|
|
|
|
14 => { 0 => "четырнадцать", 1 => 1}, |
44
|
|
|
|
|
|
|
15 => { 0 => "пятнадцать", 1 => 1}, |
45
|
|
|
|
|
|
|
16 => { 0 => "шестнадцать", 1 => 1}, |
46
|
|
|
|
|
|
|
17 => { 0 => "семнадцать", 1 => 1}, |
47
|
|
|
|
|
|
|
18 => { 0 => "восемнадцать", 1 => 1}, |
48
|
|
|
|
|
|
|
19 => { 0 => "девятнадцать", 1 => 1}, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
1 => { |
51
|
|
|
|
|
|
|
2 => { 0 => "двадцать", 1 => 1}, |
52
|
|
|
|
|
|
|
3 => { 0 => "тридцать", 1 => 1}, |
53
|
|
|
|
|
|
|
4 => { 0 => "сорок", 1 => 1}, |
54
|
|
|
|
|
|
|
5 => { 0 => "пятьдесят", 1 => 1}, |
55
|
|
|
|
|
|
|
6 => { 0 => "шестьдесят", 1 => 1}, |
56
|
|
|
|
|
|
|
7 => { 0 => "семьдесят", 1 => 1}, |
57
|
|
|
|
|
|
|
8 => { 0 => "восемьдесят", 1 => 1}, |
58
|
|
|
|
|
|
|
9 => { 0 => "девяносто", 1 => 1}, |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
2 => { |
61
|
|
|
|
|
|
|
1 => { 0 => "сто", 1 => 1}, |
62
|
|
|
|
|
|
|
2 => { 0 => "двести", 1 => 1}, |
63
|
|
|
|
|
|
|
3 => { 0 => "триста", 1 => 1}, |
64
|
|
|
|
|
|
|
4 => { 0 => "четыреста", 1 => 1}, |
65
|
|
|
|
|
|
|
5 => { 0 => "пятьсот", 1 => 1}, |
66
|
|
|
|
|
|
|
6 => { 0 => "шестьсот", 1 => 1}, |
67
|
|
|
|
|
|
|
7 => { 0 => "семьсот", 1 => 1}, |
68
|
|
|
|
|
|
|
8 => { 0 => "восемьсот", 1 => 1}, |
69
|
|
|
|
|
|
|
9 => { 0 => "девятьсот", 1 => 1} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
%nom = ( |
74
|
|
|
|
|
|
|
0 => {0 => "копейки", 1 => "копеек", 2 => "одна копейка", 3 => "две копейки"}, |
75
|
|
|
|
|
|
|
1 => {0 => "рубля", 1 => "рублей", 2 => "один рубль", 3 => "два рубля"}, |
76
|
|
|
|
|
|
|
2 => {0 => "тысячи", 1 => "тысяч", 2 => "одна тысяча", 3 => "две тысячи"}, |
77
|
|
|
|
|
|
|
3 => {0 => "миллиона", 1 => "миллионов", 2 => "один миллион", 3 => "два миллиона"}, |
78
|
|
|
|
|
|
|
4 => {0 => "миллиарда",1 => "миллиардов",2 => "один миллиард",3 => "два миллиарда"}, |
79
|
|
|
|
|
|
|
5 => {0 => "триллиона",1 => "триллионов",2 => "один триллион",3 => "два триллиона"} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $out_rub; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# }}} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# {{{ rur_in_words |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub rur_in_words :Export { |
89
|
6
|
|
100
|
6
|
1
|
3162
|
my ($sum) = shift // 0; |
90
|
6
|
|
|
|
|
9
|
my ($retval, $i, $sum_rub, $sum_kop); |
91
|
|
|
|
|
|
|
|
92
|
6
|
|
|
|
|
7
|
$retval = ""; |
93
|
6
|
100
|
|
|
|
17
|
$out_rub = ($sum >= 1) ? 0 : 1; |
94
|
6
|
|
|
|
|
18
|
$sum_rub = sprintf("%d", $sum); |
95
|
6
|
50
|
|
|
|
19
|
$sum_rub-- if (($sum_rub - $sum) > 0); |
96
|
6
|
|
|
|
|
53
|
$sum_kop = sprintf("%0.2f", ($sum - $sum_rub)) * 100; |
97
|
6
|
|
|
|
|
15
|
my $kop = get_string($sum_kop, 0); |
98
|
|
|
|
|
|
|
|
99
|
6
|
|
66
|
|
|
71
|
for ($i=1; $i<6 && $sum_rub >= 1; $i++) { |
100
|
4
|
|
|
|
|
7
|
my $sum_tmp = $sum_rub / 1000; |
101
|
4
|
|
|
|
|
23
|
my $sum_part = sprintf("%0.3f", $sum_tmp - sprintf("%d", $sum_tmp) ) * 1000; |
102
|
4
|
|
|
|
|
8
|
$sum_rub = sprintf("%d", $sum_tmp); |
103
|
|
|
|
|
|
|
|
104
|
4
|
50
|
|
|
|
12
|
$sum_rub-- if ($sum_rub - $sum_tmp > 0); |
105
|
4
|
|
|
|
|
9
|
$retval = get_string($sum_part, $i)." ".$retval; |
106
|
|
|
|
|
|
|
} |
107
|
6
|
50
|
|
|
|
20
|
$retval .= " рублей" if ($out_rub == 0); |
108
|
6
|
|
|
|
|
14
|
$retval .= " ".$kop; |
109
|
6
|
|
|
|
|
42
|
$retval =~ s/\s+/ /g; |
110
|
|
|
|
|
|
|
|
111
|
6
|
|
|
|
|
20
|
return $retval; |
112
|
1
|
|
|
1
|
|
6
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# }}} |
115
|
|
|
|
|
|
|
# {{{ get_string |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_string :Export{ |
118
|
17
|
|
100
|
17
|
1
|
3798
|
my $sum = shift // return; |
119
|
15
|
|
|
|
|
18
|
my $nominal = shift; |
120
|
15
|
|
|
|
|
22
|
my ($retval, $nom) = ('', -1); |
121
|
|
|
|
|
|
|
|
122
|
15
|
50
|
66
|
|
|
122
|
if ((!$nominal && $sum < 100) || ($nominal > 0 && $nominal < 6 && $sum < 1000)) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
123
|
15
|
|
|
|
|
41
|
my $s2 = sprintf("%d", $sum / 100); |
124
|
15
|
100
|
|
|
|
33
|
if ($s2 > 0) { |
125
|
2
|
|
|
|
|
8
|
$retval .= ' '.$diw{2}{$s2}{0}; |
126
|
2
|
|
|
|
|
5
|
$nom = $diw{2}{$s2}{1}; |
127
|
|
|
|
|
|
|
} |
128
|
15
|
|
|
|
|
33
|
my $sx = sprintf("%d", $sum - $s2 * 100); |
129
|
15
|
50
|
|
|
|
37
|
$sx-- if ($sx - ($sum - $s2*100) > 0); |
130
|
|
|
|
|
|
|
|
131
|
15
|
100
|
100
|
|
|
92
|
if (($sx<20 && $sx>0) || ($sx == 0 && !$nominal)) { |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
132
|
12
|
|
|
|
|
44
|
$retval .= " ".$diw{0}{$sx}{0}; |
133
|
12
|
|
|
|
|
30
|
$nom = $diw{0}{$sx}{1}; |
134
|
|
|
|
|
|
|
} else { |
135
|
3
|
|
|
|
|
8
|
my $s1 = sprintf("%d", $sx / 10); |
136
|
3
|
50
|
|
|
|
11
|
$s1-- if (($s1 - $sx/10) > 0); |
137
|
3
|
|
|
|
|
10
|
my $s0 = sprintf("%d", $sum - $s2*100 - $s1*10 + 0.5); |
138
|
3
|
50
|
|
|
|
7
|
if ($s1 > 0) { |
139
|
3
|
|
|
|
|
12
|
$retval .= ' '.$diw{1}{$s1}{0}; |
140
|
3
|
|
|
|
|
8
|
$nom = $diw{1}{$s1}{1}; |
141
|
|
|
|
|
|
|
} |
142
|
3
|
100
|
|
|
|
27
|
if ($s0 > 0) { |
143
|
2
|
|
|
|
|
22
|
$retval .= ' '.$diw{0}{$s0}{0}; |
144
|
2
|
|
|
|
|
5
|
$nom = $diw{0}{$s0}{1}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
15
|
50
|
|
|
|
100
|
if ($nom >= 0) { |
149
|
15
|
100
|
|
|
|
54
|
$retval .= defined $nominal ? ' '.$nom{$nominal}{$nom} : ''; |
150
|
15
|
100
|
100
|
|
|
63
|
$out_rub = 1 if (defined $nominal && $nominal == 1); |
151
|
|
|
|
|
|
|
} |
152
|
15
|
|
|
|
|
92
|
$retval =~ s/^\s*//g; |
153
|
15
|
|
|
|
|
110
|
$retval =~ s/\s*$//g; |
154
|
|
|
|
|
|
|
|
155
|
15
|
|
|
|
|
62
|
return $retval; |
156
|
1
|
|
|
1
|
|
634
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# }}} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |