This commit was generated by cvs2svn to compensate for changes in r3880,
[freeside.git] / sql-ledger / sql-ledger / locale / de / 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:
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 => 'Null',
35                     1 => 'ein',
36                     2 => 'zwei',
37                     3 => 'drei',
38                     4 => 'vier',
39                     5 => 'fünf',
40                     6 => 'sechs',
41                     7 => 'sieben',
42                     8 => 'acht',
43                     9 => 'neun',
44                    10 => 'zehn',
45                    11 => 'elf',
46                    12 => 'zwölf',
47                    13 => 'dreizehn',
48                    14 => 'vierzehn',
49                    15 => 'fünfzehn',
50                    16 => 'sechzehn',
51                    17 => 'siebzehn',
52                    18 => 'achtzehn',
53                    19 => 'neunzehn',
54                    20 => 'zwanzig',
55                    30 => 'dreissig',
56                    40 => 'vierzig',
57                    50 => 'fünfzig',
58                    60 => 'sechzig',
59                    70 => 'siebzig',
60                    80 => 'achtzig',
61                    90 => 'neunzig',
62                 10**2 => 'hundert',
63                 10**3 => 'tausend',
64                 10**6 => 'million',
65                 10**9 => 'milliarde',
66                10**12 => 'billion'
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 //, abs($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   my $belowhundred = !$#numblock;
94   
95   while (@numblock) {
96
97     $i = $#numblock;
98     @num = split //, $numblock[$i];
99     $appendn = "";
100     
101     $numblock[$i] *= 1;
102     
103     if ($numblock[$i] == 0) {
104       pop @numblock;
105       next;
106     }
107    
108     if ($numblock[$i] > 99) {
109       # the one from hundreds
110       push @textnumber, $self->{numbername}{$num[0]};
111      
112       # add hundred designation
113       push @textnumber, $self->{numbername}{10**2};
114
115       # reduce numblock
116       $numblock[$i] -= $num[0] * 100;
117     }
118     
119     $appendn = 'en' if ($i == 2);
120     $appendn = 'n' if ($i > 2);
121
122     if ($numblock[$i] > 9) {
123       # tens
124       push @textnumber, $self->format_ten($numblock[$i], $belowhundred);
125     } elsif ($numblock[$i] > 1) {
126       # ones
127       push @textnumber, $self->{numbername}{$numblock[$i]};
128     } elsif ($numblock[$i] == 1) {
129       if ($i == 0) {
130         push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
131       } else {
132         if ($i >= 2) {
133           push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
134         } else {
135           push @textnumber, $self->{numbername}{$numblock[$i]};
136         }
137       }
138       $appendn = "";
139     }
140     
141     # add thousand, million
142     if ($i) {
143       $amount = 10**($i * 3);
144       push @textnumber, $self->{numbername}{$amount}.$appendn;
145     }
146     
147     pop @numblock;
148     
149   }
150
151   join '', @textnumber;
152
153 }
154
155
156 sub format_ten {
157   my ($self, $amount, $belowhundred) = @_;
158   
159   my $textnumber = "";
160   my @num = split //, $amount;
161
162   if ($amount > 20) {
163     if ($num[1] == 0) { 
164       $textnumber = $self->{numbername}{$amount}; 
165     } else {
166       if ($belowhundred) {
167         $amount = $num[0] * 10;
168         $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
169       } else {
170         $amount = $num[0] * 10;
171         $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
172         $textnumber .= 's' if ($num[1] == 1);
173       }
174     }
175   } else {
176     $textnumber = $self->{numbername}{$amount};
177   }
178   
179   $textnumber;
180   
181 }
182
183
184 1;
185