summaryrefslogtreecommitdiff
path: root/locale/ee/Num2text
blob: fcb793bd1230e4214916bbc7e310572f639813f2 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2003
  4. #
  5. # Author: Dieter Simader
  6. # Email: dsimader@sql-ledger.org
  7. # Web: http://www.ledgersmb.org/
  8. #
  9. # Contributors: Mario R. Pizzolanti <mario@zavood.ee>
  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. # written for check and receipt printing
  26. # it returns a properly formatted text string
  27. # for a number up to 10**9
  28. sub init {
  29. my $self = shift;
  30. %{ $self->{numbername} } =
  31. (0 => 'null',
  32. 1 => 'üks',
  33. 2 => 'kaks',
  34. 3 => 'kolm',
  35. 4 => 'neli',
  36. 5 => 'viis',
  37. 6 => 'kuus',
  38. 7 => 'seitse',
  39. 8 => 'kaheksa',
  40. 9 => 'üheksa',
  41. 10 => 'kümme',
  42. 10**2 => 'sada',
  43. 10**3 => 'tuhat',
  44. 10**6 => 'miljon',
  45. 10**9 => 'miljard',
  46. 10**12 => 'biljon'
  47. );
  48. }
  49. sub num2text {
  50. my ($self, $amount) = @_;
  51. return $self->{numbername}{0} unless $amount;
  52. my @textnumber = ();
  53. # split amount into chunks of 3
  54. my @num = reverse split //, abs($amount);
  55. my @numblock = ();
  56. my ($i, $appendit);
  57. my @a = ();
  58. while (@num) {
  59. @a = ();
  60. for (1 .. 3) {
  61. push @a, shift @num;
  62. }
  63. push @numblock, join / /, reverse @a;
  64. }
  65. while (@numblock) {
  66. $i = $#numblock;
  67. $numblock[$i] *= 1;
  68. @num = split //, $numblock[$i];
  69. $appendit = "it";
  70. $hundred = 0;
  71. if ($numblock[$i] == 0) {
  72. pop @numblock;
  73. next;
  74. }
  75. if ($numblock[$i] > 99) {
  76. # the one from hundreds
  77. push @textnumber, "$self->{numbername}{$num[0]}$self->{numbername}{10**2}";
  78. # reduce numblock
  79. $numblock[$i] -= $num[0] * 100;
  80. @num = split //, $numblock[$i];
  81. $hundred = 1;
  82. }
  83. if ($numblock[$i] > 19) {
  84. # 20 - 99
  85. push @textnumber, "$self->{numbername}{$num[0]}kümmend";
  86. @num = split //, $numblock[$i];
  87. push @textnumber, $self->{numbername}{$num[1]} if $num[1] > 0;
  88. } elsif ($numblock[$i] > 10) {
  89. # 11 - 19
  90. if ($hundred) {
  91. @num = split //, $numblock[$i];
  92. }
  93. $num = $num[1];
  94. push @textnumber, "$self->{numbername}{$num}teist";
  95. } elsif ($numblock[$i] > 1) {
  96. # ones
  97. push @textnumber, $self->{numbername}{$numblock[$i]};
  98. } elsif ($numblock[$i] == 1) {
  99. push @textnumber, $self->{numbername}{$num[0]};
  100. $appendit = "";
  101. }
  102. # add thousand, million
  103. if ($i) {
  104. $amount = 10**($i * 3);
  105. $appendit = ($i == 1) ? "" : $appendit;
  106. push @textnumber, "$self->{numbername}{$amount}$appendit";
  107. }
  108. pop @numblock;
  109. }
  110. join ' ', @textnumber;
  111. }
  112. 1;