line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2008-2009 Pan Yu (xiaocong@vip.163.com). |
3
|
|
|
|
|
|
|
# All rights reserved. |
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
5
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Money::Chinese; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
119620
|
use 5.006; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
179
|
|
11
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
182
|
|
12
|
5
|
|
|
5
|
|
30
|
use vars qw($VERSION); |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
327
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '1.10'; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
25
|
use Carp; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
5151
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @Chinese = qw( Áã Ò¼ ·¡ Èþ ËÁ Îé ½ Æâ °Æ ¾Á ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
4
|
|
|
4
|
0
|
47
|
my $class = shift; |
22
|
4
|
|
33
|
|
|
33
|
my $type = ref($class) || $class; |
23
|
4
|
|
|
|
|
12
|
my $arg_ref = { @_ }; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
15
|
my $self = bless {}, $type; |
26
|
4
|
|
|
|
|
16
|
$self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub convert { |
30
|
13
|
|
|
13
|
0
|
39
|
my $self = shift; |
31
|
13
|
|
|
|
|
49
|
my $money = shift; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# replace comma and space |
34
|
13
|
|
|
|
|
42
|
$money =~ s/[,(?:\s)+]//g; |
35
|
|
|
|
|
|
|
|
36
|
13
|
50
|
|
|
|
69
|
croak "An Arabic numeral with the format of 'xxxx.xx' is expected" |
37
|
|
|
|
|
|
|
unless ($money =~ /^(?:\d)+(?:\.(?:\d)+)?$/); |
38
|
13
|
50
|
|
|
|
51
|
croak "A non zero Arabic numeral is expected" if ($money == 0); |
39
|
|
|
|
|
|
|
|
40
|
13
|
|
|
|
|
118
|
$self->{integer} = undef; |
41
|
13
|
|
|
|
|
26
|
$self->{decimal} = undef; |
42
|
13
|
|
|
|
|
21
|
$self->{Chinese_integer} = undef; |
43
|
13
|
|
|
|
|
17
|
$self->{Chinese_decimal} = undef; |
44
|
|
|
|
|
|
|
|
45
|
13
|
|
|
|
|
53
|
($self->{integer}, $self->{decimal}) = split /\./, $money; |
46
|
|
|
|
|
|
|
|
47
|
13
|
100
|
|
|
|
66
|
$self->_integer if ($self->{integer} != 0); |
48
|
13
|
100
|
100
|
|
|
69
|
$self->_decimal if (defined $self->{decimal} && $self->{decimal} != 0); |
49
|
13
|
|
|
|
|
35
|
$self->_print; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _print { |
53
|
13
|
|
|
13
|
|
15
|
my $self = shift; |
54
|
13
|
|
|
|
|
17
|
my $result; |
55
|
|
|
|
|
|
|
|
56
|
13
|
100
|
|
|
|
36
|
$result = $self->{Chinese_integer} if ($self->{integer} != 0); |
57
|
13
|
100
|
100
|
|
|
62
|
if (defined $self->{decimal} && $self->{decimal} != 0) { |
58
|
5
|
|
|
|
|
13
|
$result .= $self->{Chinese_decimal}; |
59
|
|
|
|
|
|
|
}else{ |
60
|
8
|
|
|
|
|
12
|
$result .= 'Õû'; |
61
|
|
|
|
|
|
|
} |
62
|
13
|
|
|
|
|
69
|
return $result; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _decimal { |
66
|
5
|
|
|
5
|
|
7
|
my $self = shift; |
67
|
5
|
|
|
|
|
7
|
my ($cent, @cent); |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
14
|
$cent[0] = substr( $self->{decimal}, 0 , 1 ); |
70
|
5
|
50
|
|
|
|
24
|
$cent[1] = substr( $self->{decimal}, 1 , 1 ) if (length($self->{decimal}) != 1); |
71
|
5
|
50
|
|
|
|
20
|
$cent = ($cent[0] == 0)? $Chinese[0]:$Chinese[$cent[0]] . '½Ç'; |
72
|
5
|
50
|
|
|
|
18
|
$cent .= $Chinese[$cent[1]] . '·Ö' if ($cent[1]); |
73
|
|
|
|
|
|
|
|
74
|
5
|
|
|
|
|
13
|
$self->{Chinese_decimal} = $cent; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _integer { |
78
|
12
|
|
|
12
|
|
17
|
my $self = shift; |
79
|
12
|
|
|
|
|
14
|
my (@digit, @result, $result); |
80
|
12
|
|
|
|
|
20
|
my $money = $self->{integer}; |
81
|
|
|
|
|
|
|
|
82
|
12
|
|
|
|
|
46
|
for (my $i = 0; length($money) > 0; $i++) { |
83
|
23
|
|
|
|
|
48
|
$digit[$i] = substr( $money, -4 , 4 ); |
84
|
23
|
|
|
|
|
34
|
substr( $money, -4 , 4 ) = ''; |
85
|
23
|
100
|
|
|
|
101
|
$digit[$i] = '0'x(4 - length($digit[$i])) . $digit[$i] if (length($digit[$i]) != 4); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
12
|
|
|
|
|
15
|
my $i = 0; |
89
|
12
|
|
|
|
|
22
|
foreach (@digit) { |
90
|
23
|
|
|
|
|
28
|
$i++; |
91
|
23
|
100
|
|
|
|
42
|
next if ($_ eq '0000'); |
92
|
20
|
|
|
|
|
52
|
m/(\d)(\d)(\d)(\d)/; |
93
|
20
|
|
|
|
|
23
|
my $cn; |
94
|
20
|
|
|
|
|
44
|
my $tail = ''; |
95
|
20
|
100
|
|
|
|
77
|
$cn = ($1 == 0)? $Chinese[0]:$Chinese[$1] . "Ǫ"; |
96
|
20
|
100
|
|
|
|
48
|
$cn .= ($2 == 0)? $Chinese[0]:$Chinese[$2] . "°Û"; |
97
|
20
|
100
|
|
|
|
53
|
$cn .= ($3 == 0)? $Chinese[0]:$Chinese[$3] . "Ê°"; |
98
|
20
|
100
|
|
|
|
45
|
$cn .= ($4 == 0)? '':$Chinese[$4]; |
99
|
20
|
100
|
|
|
|
51
|
if ($i%2 == 0) { |
100
|
7
|
|
|
|
|
8
|
$tail = 'Íò'; |
101
|
7
|
100
|
|
|
|
26
|
$tail .= 'Áã' if ($4 == 0); |
102
|
|
|
|
|
|
|
} |
103
|
20
|
100
|
|
|
|
36
|
if($i > 2) { |
104
|
3
|
|
|
|
|
5
|
$tail .= 'ÒÚ'; |
105
|
3
|
50
|
|
|
|
11
|
$tail .= 'Áã' if ($4 == 0); |
106
|
3
|
|
|
|
|
9
|
$tail =~ s/ÁãÒÚ/ÒÚ/; |
107
|
|
|
|
|
|
|
} |
108
|
20
|
|
|
|
|
73
|
$cn =~ s/(?:Áã)+$//; |
109
|
20
|
|
|
|
|
62
|
unshift (@result, "$cn$tail"); |
110
|
|
|
|
|
|
|
} |
111
|
12
|
|
|
|
|
27
|
$result = join '',@result; |
112
|
12
|
|
|
|
|
96
|
$result =~ s/(?:Áã){2,}/Áã/g; |
113
|
12
|
|
|
|
|
42
|
$result =~ s/^(?:Áã)+//; |
114
|
|
|
|
|
|
|
|
115
|
12
|
|
|
|
|
75
|
$result =~ s/(?:Áã)+$//; |
116
|
12
|
|
|
|
|
16
|
$result .= 'Ôª'; |
117
|
|
|
|
|
|
|
|
118
|
12
|
|
|
|
|
58
|
$self->{Chinese_integer} = $result; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |