Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / 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., 51 Franklin Street, Fifth Floor, Boston,
23 # MA 02110-1335, USA.
24 #======================================================================
25 #
26 # this is a variation of the Lingua package
27 # written for check and receipt printing
28 # it returns a properly formatted text string
29 # for a number up to 10**12
30
31 sub init {
32   my $self = shift;
33
34   %{ $self->{numbername} } =
35                    (0 => 'Null',
36                     1 => 'ein',
37                     2 => 'zwei',
38                     3 => 'drei',
39                     4 => 'vier',
40                     5 => 'fünf',
41                     6 => 'sechs',
42                     7 => 'sieben',
43                     8 => 'acht',
44                     9 => 'neun',
45                    10 => 'zehn',
46                    11 => 'elf',
47                    12 => 'zwölf',
48                    13 => 'dreizehn',
49                    14 => 'vierzehn',
50                    15 => 'fünfzehn',
51                    16 => 'sechzehn',
52                    17 => 'siebzehn',
53                    18 => 'achtzehn',
54                    19 => 'neunzehn',
55                    20 => 'zwanzig',
56                    30 => 'dreissig',
57                    40 => 'vierzig',
58                    50 => 'fünfzig',
59                    60 => 'sechzig',
60                    70 => 'siebzig',
61                    80 => 'achtzig',
62                    90 => 'neunzig',
63                 10**2 => 'hundert',
64                 10**3 => 'tausend',
65                 10**6 => 'million',
66                 10**9 => 'milliarde',
67                10**12 => 'billion'
68                 );
69
70 }
71
72
73 sub num2text {
74   my ($self, $amount) = @_;
75
76   return $self->{numbername}{0} unless $amount;
77
78   my @textnumber = ();
79
80   # split amount into chunks of 3
81   my @num = reverse split //, $amount;
82   my @numblock = ();
83   my ($i, $appendn);
84   my @a = ();
85
86   while (@num) {
87     @a = ();
88     for (1 .. 3) {
89       push @a, shift @num;
90     }
91     push @numblock, join / /, reverse @a;
92   }
93   
94   my $belowhundred = !$#numblock;
95   
96   while (@numblock) {
97
98     $i = $#numblock;
99     @num = split //, $numblock[$i];
100     $appendn = "";
101     
102     $numblock[$i] *= 1;
103     
104     if ($numblock[$i] == 0) {
105       pop @numblock;
106       next;
107     }
108    
109     if ($numblock[$i] > 99) {
110       # the one from hundreds
111       push @textnumber, $self->{numbername}{$num[0]};
112      
113       # add hundred designation
114       push @textnumber, $self->{numbername}{10**2};
115
116       # reduce numblock
117       $numblock[$i] -= $num[0] * 100;
118     }
119     
120     $appendn = 'en' if ($i == 2);
121     $appendn = 'n' if ($i > 2);
122
123     if ($numblock[$i] > 9) {
124       # tens
125       push @textnumber, $self->format_ten($numblock[$i], $belowhundred);
126     } elsif ($numblock[$i] > 1) {
127       # ones
128       push @textnumber, $self->{numbername}{$numblock[$i]};
129     } elsif ($numblock[$i] == 1) {
130       if ($i == 0) {
131         push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
132       } else {
133         if ($i >= 2) {
134           push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
135         } else {
136           push @textnumber, $self->{numbername}{$numblock[$i]};
137         }
138       }
139       $appendn = "";
140     }
141     
142     # add thousand, million
143     if ($i) {
144       $amount = 10**($i * 3);
145       push @textnumber, $self->{numbername}{$amount}.$appendn;
146     }
147     
148     pop @numblock;
149     
150   }
151
152   join '', @textnumber;
153
154 }
155
156
157 sub format_ten {
158   my ($self, $amount, $belowhundred) = @_;
159   
160   my $textnumber = "";
161   my @num = split //, $amount;
162
163   if ($amount > 20) {
164     if ($num[1] == 0) { 
165       $textnumber = $self->{numbername}{$amount}; 
166     } else {
167       if ($belowhundred) {
168         $amount = $num[0] * 10;
169         $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
170       } else {
171         $amount = $num[0] * 10;
172         $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
173         $textnumber .= 's' if ($num[1] == 1);
174       }
175     }
176   } else {
177     $textnumber = $self->{numbername}{$amount};
178   }
179   
180   $textnumber;
181   
182 }
183
184
185 1;
186