summaryrefslogtreecommitdiff
path: root/locale/be_nl/Num2text
blob: 7bf3208cbcd2cd22ab5c9f6a8c606fa160963bfb (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://sourceforge.net/projects/ledger-smb/
  8. #
  9. # Contributors: Paul Tammes <finance@bermuda-holding.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 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 => 'nul',
  33. 1 => 'een',
  34. 2 => 'twee',
  35. 3 => 'drie',
  36. 4 => 'vier',
  37. 5 => 'vijf',
  38. 6 => 'zes',
  39. 7 => 'zeven',
  40. 8 => 'acht',
  41. 9 => 'negen',
  42. 10 => 'tien',
  43. 11 => 'elf',
  44. 12 => 'twalf',
  45. 13 => 'dertien',
  46. 14 => 'veertien',
  47. 15 => 'vijftien',
  48. 16 => 'zestien',
  49. 17 => 'zeventien',
  50. 18 => 'achtien',
  51. 19 => 'negentien',
  52. 20 => 'twintig',
  53. 30 => 'dertig',
  54. 40 => 'veertig',
  55. 50 => 'vijftig',
  56. 60 => 'zestig',
  57. 70 => 'zeventig',
  58. 80 => 'tachtig',
  59. 90 => 'negentig',
  60. 10**2 => 'honderd',
  61. 10**3 => 'duizend',
  62. 10**6 => 'miljoen',
  63. 10**9 => 'miljard',
  64. 10**12 => 'biljoen'
  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. while (@numblock) {
  84. $i = $#numblock;
  85. @num = split //, $numblock[$i];
  86. $numblock[$i] *= 1;
  87. if ($numblock[$i] == 0) {
  88. pop @numblock;
  89. next;
  90. }
  91. if ($numblock[$i] > 99) {
  92. # the one from hundreds
  93. push @textnumber, $self->{numbername}{$num[0]};
  94. # add hundred designation
  95. push @textnumber, $self->{numbername}{10**2};
  96. # reduce numblock
  97. $numblock[$i] -= $num[0] * 100;
  98. }
  99. if ($numblock[$i] > 9) {
  100. # tens
  101. push @textnumber, $self->format_ten($numblock[$i]);
  102. } else {
  103. # ones
  104. push @textnumber, $self->{numbername}{$numblock[$i]};
  105. }
  106. # add thousand, million
  107. if ($i) {
  108. $amount = 10**($i * 3);
  109. push @textnumber, $self->{numbername}{$amount};
  110. }
  111. pop @numblock;
  112. }
  113. push @textnumber, '**';
  114. join '', @textnumber;
  115. }
  116. sub format_ten {
  117. my ($self, $amount) = @_;
  118. my $textnumber = "";
  119. my @num = split //, $amount;
  120. if ($amount > 20) {
  121. # reverse one and ten and glue together with 'en'
  122. $amount = $num[0] * 10;
  123. $textnumber = $self->{numbername}{$num[1]}.'en'.$self->{numbername}{$amount};
  124. } else {
  125. $textnumber = $self->{numbername}{$amount};
  126. }
  127. $textnumber;
  128. }
  129. 1;