summaryrefslogtreecommitdiff
path: root/locale/legacy/de/Num2text
blob: 29d4219bad575b0b7111db2826ac9822f929a097 (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:
  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. sub init {
  30. my $self = shift;
  31. %{ $self->{numbername} } =
  32. (0 => 'Null',
  33. 1 => 'ein',
  34. 2 => 'zwei',
  35. 3 => 'drei',
  36. 4 => 'vier',
  37. 5 => 'f�nf',
  38. 6 => 'sechs',
  39. 7 => 'sieben',
  40. 8 => 'acht',
  41. 9 => 'neun',
  42. 10 => 'zehn',
  43. 11 => 'elf',
  44. 12 => 'zw�lf',
  45. 13 => 'dreizehn',
  46. 14 => 'vierzehn',
  47. 15 => 'f�nfzehn',
  48. 16 => 'sechzehn',
  49. 17 => 'siebzehn',
  50. 18 => 'achtzehn',
  51. 19 => 'neunzehn',
  52. 20 => 'zwanzig',
  53. 30 => 'dreissig',
  54. 40 => 'vierzig',
  55. 50 => 'f�nfzig',
  56. 60 => 'sechzig',
  57. 70 => 'siebzig',
  58. 80 => 'achtzig',
  59. 90 => 'neunzig',
  60. 10**2 => 'hundert',
  61. 10**3 => 'tausend',
  62. 10**6 => 'million',
  63. 10**9 => 'milliarde',
  64. 10**12 => 'billion'
  65. );
  66. }
  67. sub num2text {
  68. my ($self, $amount) = @_;
  69. return $self->{numbername}{0} unless $amount;
  70. my @textnumber = ();
  71. # split amount into chunks of 3
  72. my @num = reverse split //, abs($amount);
  73. my @numblock = ();
  74. my ($i, $appendn);
  75. my @a = ();
  76. while (@num) {
  77. @a = ();
  78. for (1 .. 3) {
  79. push @a, shift @num;
  80. }
  81. push @numblock, join / /, reverse @a;
  82. }
  83. my $belowhundred = !$#numblock;
  84. while (@numblock) {
  85. $i = $#numblock;
  86. @num = split //, $numblock[$i];
  87. $appendn = "";
  88. $numblock[$i] *= 1;
  89. if ($numblock[$i] == 0) {
  90. pop @numblock;
  91. next;
  92. }
  93. if ($numblock[$i] > 99) {
  94. # the one from hundreds
  95. push @textnumber, $self->{numbername}{$num[0]};
  96. # add hundred designation
  97. push @textnumber, $self->{numbername}{10**2};
  98. # reduce numblock
  99. $numblock[$i] -= $num[0] * 100;
  100. }
  101. $appendn = 'en' if ($i == 2);
  102. $appendn = 'n' if ($i > 2);
  103. if ($numblock[$i] > 9) {
  104. # tens
  105. push @textnumber, $self->format_ten($numblock[$i], $belowhundred);
  106. } elsif ($numblock[$i] > 1) {
  107. # ones
  108. push @textnumber, $self->{numbername}{$numblock[$i]};
  109. } elsif ($numblock[$i] == 1) {
  110. if ($i == 0) {
  111. push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
  112. } else {
  113. if ($i >= 2) {
  114. push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
  115. } else {
  116. push @textnumber, $self->{numbername}{$numblock[$i]};
  117. }
  118. }
  119. $appendn = "";
  120. }
  121. # add thousand, million
  122. if ($i) {
  123. $amount = 10**($i * 3);
  124. push @textnumber, $self->{numbername}{$amount}.$appendn;
  125. }
  126. pop @numblock;
  127. }
  128. join '', @textnumber;
  129. }
  130. sub format_ten {
  131. my ($self, $amount, $belowhundred) = @_;
  132. my $textnumber = "";
  133. my @num = split //, $amount;
  134. if ($amount > 20) {
  135. if ($num[1] == 0) {
  136. $textnumber = $self->{numbername}{$amount};
  137. } else {
  138. if ($belowhundred) {
  139. $amount = $num[0] * 10;
  140. $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
  141. } else {
  142. $amount = $num[0] * 10;
  143. $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
  144. $textnumber .= 's' if ($num[1] == 1);
  145. }
  146. }
  147. } else {
  148. $textnumber = $self->{numbername}{$amount};
  149. }
  150. $textnumber;
  151. }
  152. 1;