File Coverage

blib/lib/Lingua/IND/Numbers.pm
Criterion Covered Total %
statement 49 49 100.0
branch 22 22 100.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 80 80 100.0


line stmt bran cond sub pod time code
1             package Lingua::IND::Numbers;
2              
3             $Lingua::IND::Numbers::VERSION = '0.09';
4             $Lingua::IND::Numbers::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Lingua::IND::Numbers - Indian Numbering System representation
9              
10             =head1 VERSION
11              
12             Version 0.09
13              
14             =cut
15              
16 3     3   55659 use 5.006;
  3         11  
17 3     3   2444 use Data::Dumper;
  3         27028  
  3         246  
18              
19 3     3   1656 use bignum;
  3         16493  
  3         17  
20 3     3   192649 use Moo;
  3         41043  
  3         21  
21 3     3   6802 use namespace::clean;
  3         38222  
  3         19  
22              
23             has 'chart' => (is => 'ro', default => sub { _get_chart() });
24             has 'units' => (is => 'ro', default => sub { _get_units() });
25              
26             =head1 DESCRIPTION
27              
28             The Indian Numbering System is used India, Pakistan, Bangladesh, Nepal, and Sri
29             Lanka. It is based on the Vedic numbering system in which numbers over 9,999 are
30             written in two-digit groups (or a mix of two- and three-digit groups) rather than
31             the three-digit groups used in most other parts of the world. In Pakistan,they do
32             not use this numbering system in English media but only in Urdu & other regional
33             languages.
34              
35             The terms lakh (100,000) and crore (10,000,000) are used in Indian English to
36             express large numbers.
37              
38             +------------------------------------+--------------------------------------+
39             | Name | Indian Figure |
40             +------------------------------------+--------------------------------------+
41             | Shunya (Zero) | 0 |
42             | Ek (One) | 1 |
43             | Das (Ten) | 10 |
44             | Sau (One Hundres) | 100 |
45             | Hazaar (One Thousand) | 1,000 |
46             | Das Hazaar (Ten Thousand) | 10,000 |
47             | Lakh (Hundred Thousand) | 1,00,000 |
48             | Das Lakh | 10,00,000 |
49             | Crore | 1,00,00,000 |
50             | Das Crore | 10,00,00,000 |
51             | Arab (One Hundred Crore) | 1,00,00,00,000 |
52             | Das Arab (One Thousand Crore) | 10,00,00,00,000 |
53             | Kharab (Ten Thousand Crore) | 1,00,00,00,00,000 |
54             | Das Kharab (One Lakh Crore) | 10,00,00,00,00,000 |
55             | Neel (Ten Lakh Crore) | 1,00,00,00,00,00,000 |
56             | Das Neel (One Crore Crore) | 10,00,00,00,00,00,000 |
57             | Padm (Ten Crore Crore) | 1,00,00,00,00,00,00,000 |
58             | Das Padm (One Hundred Crore Crore) | 10,00,00,00,00,00,00,000 |
59             | Shankh (One Lakh Lakh Crore) | 1,00,00,00,00,00,00,00,000 |
60             +------------------------------------+--------------------------------------+
61              
62             Source: L
63              
64             =head1 NUMBERS
65              
66             For example, 150000 becomes Ek Lakh Pachaas Hazar.
67              
68             +------------+--------+ +------------+--------+ +----------+---------+
69             | Name | Number | | Name | Number | | Name | Number |
70             +------------+--------+ +------------+--------+ +----------+---------+
71             | Ek | 1 | | Egyarah | 11 | | Ekees | 21 |
72             | Do | 2 | | Barah | 12 | | Baees | 22 |
73             | Teen | 3 | | Terah | 13 | | Teyees | 23 |
74             | Chaar | 4 | | Chaudah | 14 | | Chaubees | 24 |
75             | Paanch | 5 | | Pandrah | 15 | | Pachees | 25 |
76             | Chhe | 6 | | Solah | 16 | | Chhabbis | 26 |
77             | Saat | 7 | | Satrah | 17 | | Satayees | 27 |
78             | Aath | 8 | | Attharah | 18 | | Atthaees | 28 |
79             | Nau | 9 | | Unnees | 19 | | Untees | 29 |
80             | Das | 10 | | Bees | 20 | | Tees | 30 |
81             +------------+--------+ +------------+--------+ +----------+---------+
82              
83             +------------+--------+ +------------+--------+ +-----------+--------+
84             | Name | Number | | Name | Number | | Name | Number |
85             +------------+--------+ +------------+--------+ +-----------+--------+
86             | Ektees | 31 | | Ektalees | 41 | | Ekaawan | 51 |
87             | Battees | 32 | | Beyalees | 42 | | Baawan | 52 |
88             | Taitees | 33 | | Taitalees | 43 | | Tirpan | 53 |
89             | Chautees | 34 | | Chaualees | 44 | | Chauwan | 54 |
90             | Paitees | 35 | | Paitalees | 45 | | Pachpan | 55 |
91             | Chhattess | 36 | | Chheyalees | 46 | | Chhappan | 56 |
92             | Saitees | 37 | | Saitalees | 47 | | Santawan | 57 |
93             | Artees | 38 | | Artalees | 48 | | Anthawan | 58 |
94             | Unchalees | 39 | | Unchaas | 49 | | Unsath | 59 |
95             | Chalees | 40 | | Pachaas | 50 | | Saath | 60 |
96             +------------+--------+ +------------+--------+ +-----------+------- +
97              
98             +------------+--------+ +------------+--------+ +-----------+--------+
99             | Name | Number | | Name | Number | | Name | Number |
100             +------------+--------+ +------------+--------+ +-----------+--------+
101             | Eksath | 61 | | Ekhattar | 71 | | Ekaase | 81 |
102             | Baasath | 62 | | Bahattar | 72 | | Beraase | 82 |
103             | Tirsath | 63 | | Tehattar | 73 | | Teraase | 83 |
104             | Chausath | 64 | | Chauhattar | 74 | | Chauraase | 84 |
105             | Paisath | 65 | | Pachhattar | 75 | | Pachaase | 85 |
106             | Chheyasath | 66 | | Chheyattar | 76 | | Chheyaase | 86 |
107             | Sarsath | 67 | | Satattar | 77 | | Sataase | 87 |
108             | Arsath | 68 | | Atathar | 78 | | Atthaase | 88 |
109             | Unhattar | 69 | | Unnase | 79 | | Nawaase | 89 |
110             | Sattar | 70 | | Asse | 80 | | Nabbe | 90 |
111             +------------+--------+ +------------+--------+ +-----------+--------+
112              
113             +------------+--------+
114             | Name | Number |
115             +------------+--------+
116             | Ekkaanwe | 91 |
117             | Beraanwe | 92 |
118             | Teraanwe | 93 |
119             | Chauraanwe | 94 |
120             | Panchaanwe | 95 |
121             | Chheyaanwe | 96 |
122             | Santaanwe | 97 |
123             | Anthaanwe | 98 |
124             | Neenaanwe | 99 |
125             +------------+--------+
126              
127             =head1 METHODS
128              
129             =head2 to_string($number)
130              
131             It returns the number represented in the Indian Numbering System.
132              
133             use strict; use warnings;
134             use Lingua::IND::Numbers;
135              
136             my $number = Lingua::IND::Numbers->new;
137             my $input = 123456;
138              
139             print "[$input]: ", $number->to_string($input), "\n";
140              
141             =cut
142              
143             sub to_string {
144 37     37 1 10087 my ($self, $arg) = @_;
145              
146 37 100       82 die "ERROR: Undefined number.\n" unless defined $arg;
147 36 100       184 die "ERROR: Invalid number [$arg].\n" unless ($arg =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/);
148 34 100       111 die "ERROR: Only positive number.\n" unless ($arg >= 0);
149              
150 33 100       2746 return 'Shunya' if ($arg == 0);
151              
152 32         1951 my $chart = $self->chart;
153 32         45 my $units = $self->units;
154 32         48 my $number = ($arg + 0)->bstr();
155 32 100       3193 die "ERROR: No decimal number [$arg].\n" if ($number =~ /\./);
156 31         31 my $size = length($number);
157 31 100       50 die "ERROR: No representation in Indian Numbering System.\n" if ($size > 18);
158              
159 30         1657 my @digits = split //, $number;
160 30         33 my $string = '';
161 30         33 my $index = 0;
162              
163 30         44 while ($size >= 1) {
164 69 100       3616 if ($size > 3) {
    100          
165 49 100       2469 if ($size % 2 == 0) {
166 14         1105 $index = $digits[0];
167 14         53 $string .= sprintf("%s %s ", $chart->[$index], $units->{$size});
168 14         31 $number = (join '', @digits[1..($size-1)]) + 0;
169             }
170             else {
171 35         2848 $index = sprintf("%d%d" , $digits[0], $digits[1]);
172 35         888 $string .= sprintf("%s %s ", $chart->[$index], $units->{$size});
173 35         71 $number = (join '', @digits[2..($size-1)]) + 0;
174             }
175             }
176             elsif ($size == 3) {
177 9         895 $string .= sprintf("%s %s ", $chart->[$digits[0]], $units->{$size});
178 9         28 $number = (join '', @digits[1..2]) + 0;
179             }
180             else {
181 11 100       1074 ($size == 2)
182             ?
183             ($index = sprintf("%d%d", $digits[0], $digits[1]))
184             :
185             ($index = sprintf("%d", $digits[0]));
186 11         744 $string .= sprintf("%s", $chart->[$index]);
187              
188 11         43 return $string;
189             }
190              
191 58 100       12170 if ($number > 0) {
192 39         760 @digits = split //,$number;
193 39         560 $size = scalar(@digits);
194             }
195             else {
196 19         386 $string =~ s/\s+$//;
197 19         94 return $string;
198             }
199             }
200             }
201              
202             #
203             #
204             # PRIVATE METHODS
205              
206             sub _get_chart {
207              
208             return [
209 2     2   64 '',
210             qw/Ek Do Teen Chaar Paanch Chhe Saat Aath Nau Das
211             Egyarah Barah Terah Chaudah Pandrah Solah Satrah Attharah Unnees Bees
212             Ekees Baees Teyees Chaubees Pachees Chhabbees Satayees Atthaees Untees Tees
213             Ektees Battees Taithees Chautees Paitees Chhattees Saitees Artees Unchalees Chalees
214             Ektalees Beyalees Taitalees Chaualees Paitalees Chheyalees Saitalees Artalees Unchaas Pachaas
215             Ekaawan Baawan Tirpan Chauwan Pachpan Chhappan Santawan Anthawan Unsath Saath
216             Eksath Baasath Tirsath Chausath Paisath Chheyasath Sarsath Arsath Unhattar Sattar
217             Ekhattar Bahattar Tehattar Chauhattar Pachhattar Chheyattar Satattar Atathar Unnase Asse
218             Ekaase Beraase Teraase Chauraase Pachaase Chheyaasee Sataase Atthaase Nawaase Nabbe
219             Ekkaanwe Beraanwe Teraanwe Chauraanwe Panchaanwe Chheyaanwe Santaanwe Anthaanwe Neenaanwe/];
220             }
221              
222             sub _get_units {
223              
224             return {
225 2     2   97 18 => 'Shankh', 17 => 'Padm' , 16 => 'Padm' , 15 => 'Neel',
226             14 => 'Neel' , 13 => 'Kharab', 12 => 'Kharab', 11 => 'Arab',
227             10 => 'Arab' , 9 => 'Crore' , 8 => 'Crore' , 7 => 'Lakh',
228             6 => 'Lakh' , 5 => 'Hazaar', 4 => 'Hazaar', 3 => 'Sau' };
229             }
230              
231             =head1 AUTHOR
232              
233             Mohammad S Anwar, C<< >>
234              
235             =head1 REPOSITORY
236              
237             L
238              
239             =head1 BUGS
240              
241             Please report any bugs/feature requests to C or
242             through the web interface at L.
243             I will be notified & then you'll automatically be notified of progress on your bug
244             as I make changes.
245              
246             =head1 SUPPORT
247              
248             You can find documentation for this module with the perldoc command.
249              
250             perldoc Lingua::IND::Numbers
251              
252             You can also look for information at:
253              
254             =over 4
255              
256             =item * RT: CPAN's request tracker
257              
258             L
259              
260             =item * AnnoCPAN: Annotated CPAN documentation
261              
262             L
263              
264             =item * CPAN Ratings
265              
266             L
267              
268             =item * Search CPAN
269              
270             L
271              
272             =back
273              
274             =head1 LICENSE AND COPYRIGHT
275              
276             Copyright (C) 2014 - 2015 Mohammad S Anwar.
277              
278             This program is free software; you can redistribute it and/or modify it under
279             the terms of the the Artistic License (2.0). You may obtain a copy of the full
280             license at:
281              
282             L
283              
284             Any use, modification, and distribution of the Standard or Modified Versions is
285             governed by this Artistic License.By using, modifying or distributing the Package,
286             you accept this license. Do not use, modify, or distribute the Package, if you do
287             not accept this license.
288              
289             If your Modified Version has been derived from a Modified Version made by someone
290             other than you,you are nevertheless required to ensure that your Modified Version
291             complies with the requirements of this license.
292              
293             This license does not grant you the right to use any trademark, service mark,
294             tradename, or logo of the Copyright Holder.
295              
296             This license includes the non-exclusive, worldwide, free-of-charge patent license
297             to make, have made, use, offer to sell, sell, import and otherwise transfer the
298             Package with respect to any patent claims licensable by the Copyright Holder that
299             are necessarily infringed by the Package. If you institute patent litigation
300             (including a cross-claim or counterclaim) against any party alleging that the
301             Package constitutes direct or contributory patent infringement,then this Artistic
302             License to you shall terminate on the date that such litigation is filed.
303              
304             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
305             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
306             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
307             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
308             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
309             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
310             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311              
312             =cut
313              
314             1; # End of Lingua::IND::Numbers