summaryrefslogtreecommitdiff
path: root/locale/be_fr/Num2text
blob: a9f5385bc9320a0a9bab3d076c2f3a59644d0e02 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2002
  4. #
  5. # Author: Dieter Simader
  6. # Email: dsimader@sql-ledger.org
  7. # Web: http://www.ledgersmb.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. sub init {
  29. my $self = shift;
  30. %{ $self->{numbername} } =
  31. (0 => 'Zéro',
  32. 1 => 'Un',
  33. 2 => 'Deux',
  34. 3 => 'Trois',
  35. 4 => 'Quatre',
  36. 5 => 'Cinq',
  37. 6 => 'Six',
  38. 7 => 'Sept',
  39. 8 => 'Huit',
  40. 9 => 'Neuf',
  41. 10 => 'Dix',
  42. 11 => 'Onze',
  43. 12 => 'Douze',
  44. 13 => 'Treize',
  45. 14 => 'Quatorze',
  46. 15 => 'Quinze',
  47. 16 => 'Seize',
  48. 17 => 'Dix-sept',
  49. 18 => 'Dix-huit',
  50. 19 => 'Dix-neuf',
  51. 20 => 'Vingt',
  52. 30 => 'Trente',
  53. 40 => 'Quarante',
  54. 50 => 'Cinquante',
  55. 60 => 'Soixante',
  56. 70 => 'Septante',
  57. 80 => 'Quatre-vingt',
  58. 90 => 'Nonante',
  59. 10**2 => 'Cent',
  60. 10**3 => 'Mille',
  61. 10**6 => 'Million',
  62. 10**9 => 'Milliard',
  63. 10**12 => 'Billion',
  64. );
  65. }
  66. sub num2text {
  67. my ($self, $amount) = @_;
  68. return $self->{numbername}{0} unless $amount;
  69. my @textnumber = ();
  70. # split amount into chunks of 3
  71. my @num = reverse split //, abs($amount);
  72. my @numblock = ();
  73. my @a;
  74. my $i;
  75. while (@num) {
  76. @a = ();
  77. for (1 .. 3) {
  78. push @a, shift @num;
  79. }
  80. push @numblock, join / /, reverse @a;
  81. }
  82. my $cent=0;
  83. while (@numblock) {
  84. $i = $#numblock;
  85. @num = split //, $numblock[$i];
  86. if ($numblock[$i] == 0) {
  87. pop @numblock;
  88. next;
  89. }
  90. if ($numblock[$i] > 99) {
  91. $cent=1;
  92. # the one from hundreds
  93. if ($num[0] > 1) {
  94. push @textnumber, $self->{numbername}{$num[0]};
  95. }
  96. # reduce numblock
  97. $numblock[$i] -= $num[0] * 100;
  98. # add hundred designation
  99. if ($num[0] > 1) {
  100. if($numblock[$i] > 0) {
  101. push @textnumber, $self->{numbername}{10**2};
  102. } else {
  103. push @textnumber, "$self->{numbername}{10**2}s";
  104. }
  105. } else {
  106. push @textnumber, $self->{numbername}{10**2};
  107. }
  108. }
  109. $numblock[$i] *= 1;
  110. if ($numblock[$i] > 9) {
  111. # tens
  112. push @textnumber, $self->format_ten($numblock[$i]);
  113. } elsif ($numblock[$i] > 0) {
  114. # ones
  115. if ($i == 1) {
  116. if ($cent == 1) {
  117. push @textnumber, $self->{numbername}{$numblock[$i]};
  118. }
  119. $cent = 0;
  120. } else {
  121. push @textnumber, $self->{numbername}{$numblock[$i]};
  122. }
  123. }
  124. # add thousand, million
  125. if ($i) {
  126. $num = 10**($i * 3);
  127. if ($i == 1) {
  128. push @textnumber, $self->{numbername}{$num};
  129. } elsif ($numblock[$i] > 1) {
  130. push @textnumber, "$self->{numbername}{$num}s";
  131. } else {
  132. push @textnumber, "$self->{numbername}{$num}";
  133. }
  134. }
  135. pop @numblock;
  136. }
  137. join ' ', @textnumber;
  138. }
  139. sub format_ten {
  140. my ($self, $amount) = @_;
  141. my $textnumber = "";
  142. my @num = split //, $amount;
  143. if ($amount > 20) {
  144. if ($num[0] == 8) {
  145. if ($num[1] > 0) {
  146. $textnumber = $self->{numbername}{$num[0]*10};
  147. } else {
  148. $textnumber = "$self->{numbername}{$num[0]*10}s";
  149. }
  150. } else {
  151. $textnumber = $self->{numbername}{$num[0]*10};
  152. $textnumber .= " et" if ($num[1] == 1);
  153. }
  154. $amount = $num[1];
  155. } else {
  156. $textnumber = "$self->{numbername}{$amount}";
  157. $amount = 0;
  158. }
  159. $textnumber .= " ".$self->{numbername}{$amount} if $amount;
  160. $textnumber;
  161. }
  162. 1;