This commit was generated by cvs2svn to compensate for changes in r3880,
[freeside.git] / sql-ledger / old / sql-ledger / locale / nl / Num2text
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (C) 2002
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #  Contributors: Paul Tammes <finance@bermuda-holding.com>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24 #
25 # this is a variation of the Lingua package
26 # written for check and receipt printing
27 # it returns a properly formatted text string
28 # for a number up to 10**12
29
30 sub init {
31   my $self = shift;
32
33   %{ $self->{numbername} } =
34                    (0 => 'nul',
35                     1 => 'een',
36                     2 => 'twee',
37                     3 => 'drie',
38                     4 => 'vier',
39                     5 => 'vijf',
40                     6 => 'zes',
41                     7 => 'zeven',
42                     8 => 'acht',
43                     9 => 'negen',
44                    10 => 'tien',
45                    11 => 'elf',
46                    12 => 'twalf',
47                    13 => 'dertien',
48                    14 => 'veertien',
49                    15 => 'vijftien',
50                    16 => 'zestien',
51                    17 => 'zeventien',
52                    18 => 'achtien',
53                    19 => 'negentien',
54                    20 => 'twintig',
55                    30 => 'dertig',
56                    40 => 'veertig',
57                    50 => 'vijftig',
58                    60 => 'zestig',
59                    70 => 'zeventig',
60                    80 => 'tachtig',
61                    90 => 'negentig',
62                 10**2 => 'honderd',
63                 10**3 => 'duizend',
64                 10**6 => 'miljoen',
65                 10**9 => 'miljard',
66                10**12 => 'biljoen'
67                 );
68
69 }
70
71
72 sub num2text {
73   my ($self, $amount) = @_;
74
75   return $self->{numbername}{0} unless $amount;
76
77   my @textnumber = ('**');
78
79   # split amount into chunks of 3
80   my @num = reverse split //, $amount;
81   my @numblock = ();
82   my ($i, $appendn);
83   my @a = ();
84
85   while (@num) {
86     @a = ();
87     for (1 .. 3) {
88       push @a, shift @num;
89     }
90     push @numblock, join / /, reverse @a;
91   }
92   
93   
94   while (@numblock) {
95
96     $i = $#numblock;
97     @num = split //, $numblock[$i];
98     
99     $numblock[$i] *= 1;
100     
101     if ($numblock[$i] == 0) {
102       pop @numblock;
103       next;
104     }
105    
106     if ($numblock[$i] > 99) {
107       # the one from hundreds
108       push @textnumber, $self->{numbername}{$num[0]};
109      
110       # add hundred designation
111       push @textnumber, $self->{numbername}{10**2};
112
113       # reduce numblock
114       $numblock[$i] -= $num[0] * 100;
115     }
116     
117     if ($numblock[$i] > 9) {
118       # tens
119       push @textnumber, $self->format_ten($numblock[$i]);
120     } else {
121       # ones
122       push @textnumber, $self->{numbername}{$numblock[$i]};
123     }
124     
125     # add thousand, million
126     if ($i) {
127       $amount = 10**($i * 3);
128       push @textnumber, $self->{numbername}{$amount};
129     }
130     
131     pop @numblock;
132     
133   }
134
135   push @textnumber, '**';
136   join '', @textnumber;
137
138 }
139
140
141 sub format_ten {
142   my ($self, $amount) = @_;
143   
144   my $textnumber = "";
145   my @num = split //, $amount;
146
147   if ($amount > 20) {
148     # reverse one and ten and glue together with 'en'
149     $amount = $num[0] * 10;
150     $textnumber = $self->{numbername}{$num[1]}.'en'.$self->{numbername}{$amount}; 
151   } else {
152     $textnumber = $self->{numbername}{$amount};
153   }
154   
155   $textnumber;
156   
157 }
158
159
160 1;
161