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: Bruno Leveque <bruno.leveque@net6d.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 the french code for printing numbers in text 26# 27#===================================================================== 28 29 30sub init { 31 my $self = shift; 32 33 %{ $self->{numbername} } = 34 (0 => 'Z�ro', 35 1 => 'Un', 36 2 => 'Deux', 37 3 => 'Trois', 38 4 => 'Quatre', 39 5 => 'Cinq', 40 6 => 'Six', 41 7 => 'Sept', 42 8 => 'Huit', 43 9 => 'Neuf', 44 10 => 'Dix', 45 11 => 'Onze', 46 12 => 'Douze', 47 13 => 'Treize', 48 14 => 'Quatorze', 49 15 => 'Quinze', 50 16 => 'Seize', 51 17 => 'Dix-sept', 52 18 => 'Dix-huit', 53 19 => 'Dix-neuf', 54 20 => 'Vingt', 55 30 => 'Trente', 56 40 => 'Quarante', 57 50 => 'Cinquante', 58 60 => 'Soixante', 59 70 => 'Soixante-dix', 60 80 => 'Quatre-vingt', 61 90 => 'Quatre-vingt-dix', 62 10**2 => 'Cent', 63 10**3 => 'Mille', 64 10**6 => 'Million', 65 10**9 => 'Milliard', 66 10**12 => 'Billion', 67 ); 68 69} 70 71 72sub 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 @a; 83 my $i; 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 $cent=0; 94 95 while (@numblock) { 96 97 $i = $#numblock; 98 @num = split //, $numblock[$i]; 99 100 if ($numblock[$i] == 0) { 101 pop @numblock; 102 next; 103 } 104 105 if ($numblock[$i] > 99) { 106 $cent=1; 107 108 # the one from hundreds 109 110 if ($num[0] > 1) { 111 push @textnumber, $self->{numbername}{$num[0]}; 112 } 113 114 # reduce numblock 115 $numblock[$i] -= $num[0] * 100; 116 117 # add hundred designation 118 if ($num[0] > 1) { 119 if($numblock[$i] > 0) { 120 push @textnumber, $self->{numbername}{10**2}; 121 } else { 122 push @textnumber, "$self->{numbername}{10**2}s"; 123 } 124 } else { 125 push @textnumber, $self->{numbername}{10**2}; 126 } 127 128 } 129 130 $numblock[$i] *= 1; 131 132 if ($numblock[$i] > 9) { 133 # tens 134 push @textnumber, $self->format_ten($numblock[$i]); 135 } elsif ($numblock[$i] > 0) { 136 # ones 137 if ($i == 1) { 138 if ($cent == 1) { 139 push @textnumber, $self->{numbername}{$numblock[$i]}; 140 } 141 $cent = 0; 142 } else { 143 push @textnumber, $self->{numbername}{$numblock[$i]}; 144 } 145 } 146 147 # add thousand, million 148 if ($i) { 149 $num = 10**($i * 3); 150 if ($i == 1) { 151 push @textnumber, $self->{numbername}{$num}; 152 } elsif ($numblock[$i] > 1) { 153 push @textnumber, "$self->{numbername}{$num}s"; 154 } else { 155 push @textnumber, "$self->{numbername}{$num}"; 156 } 157 } 158 159 pop @numblock; 160 161 } 162 163 join ' ', @textnumber; 164 165} 166 167 168sub format_ten { 169 my ($self, $amount) = @_; 170 171 my $textnumber = ""; 172 my @num = split //, $amount; 173 174 if ($amount > 20) { 175 if ($num[0] == 8) { 176 if ($num[1] > 0) { 177 $textnumber = $self->{numbername}{$num[0]*10}; 178 } else { 179 $textnumber = "$self->{numbername}{$num[0]*10}s"; 180 } 181 $amount = $num[1]; 182 } elsif ($num[0] == 7 || $num[0] == 9) { 183 if ($num[1] > 0) { 184 $textnumber = $self->{numbername}{($num[0]-1)*10}; 185 186 $textnumber .= " et" if ($num[1] == 1 && $num[0] == 7); 187 188 $amount -= ($num[0]-1)*10; 189 } else { 190 $textnumber = $self->{numbername}{$num[0]*10}; 191 $amount = $num[1]; 192 } 193 } else { 194 $textnumber = $self->{numbername}{$num[0]*10}; 195 $textnumber .= " et" if ($num[1] == 1); 196 $amount = $num[1]; 197 } 198 } else { 199 $textnumber = "$self->{numbername}{$amount}"; 200 $amount = 0; 201 } 202 203 $textnumber .= " ".$self->{numbername}{$amount} if $amount; 204 205 $textnumber; 206 207} 208 209 2101; 211 212