summaryrefslogtreecommitdiff
path: root/locale/legacy/ru/Num2text
blob: 013ac20407475e29331e5a2090e0ae14d6138312 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2005
  4. #
  5. # Author: Dieter Simader
  6. # Web: http://www.ledgersmb.org/
  7. #
  8. # Contributors: Vladimir Khaimin <vkhai@yandex.ru>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #======================================================================
  23. #
  24. # this is a variation of the Lingua package
  25. # written for check and receipt printing
  26. # it returns a properly formatted text string
  27. # for a number up to 10**12
  28. sub init {
  29. my $self = shift;
  30. %{ $self->{numbername} } =
  31. (0 => 'ÎÏÌØ',
  32. 1 => 'ÏÄÉÎ',
  33. 2 => 'Ä×Á',
  34. 3 => 'ÔÒÉ',
  35. 4 => 'ÞÅÔÙÒÅ',
  36. 5 => 'ÐÑÔØ',
  37. 6 => 'ÛÅÓÔØ',
  38. 7 => 'ÓÅÍØ',
  39. 8 => '×ÏÓÅÍØ',
  40. 9 => 'ÄÅ×ÑÔØ',
  41. 10 => 'ÄÅÓÑÔØ',
  42. 11 => 'ÏÄÉÎÁÄÃÁÔØ',
  43. 12 => 'Ä×ÅÎÁÄÃÁÔØ',
  44. 13 => 'ÔÒÉÎÁÄÃÁÔØ',
  45. 14 => 'ÞÅÔÙÒÎÁÄÃÁÔØ',
  46. 15 => 'ÐÑÔÎÁÄÃÁÔØ',
  47. 16 => 'ÛÅÓÔÎÁÄÃÁÔØ',
  48. 17 => 'ÓÅÍÎÁÄÃÁÔØ',
  49. 18 => '×ÏÓÅÍÎÁÄÃÁÔØ',
  50. 19 => 'ÄÅ×ÑÔÎÁÄÃÁÔØ',
  51. 20 => 'Ä×ÁÄÃÁÔØ',
  52. 30 => 'ÔÒÉÄÃÁÔØ',
  53. 40 => 'ÓÏÒÏË',
  54. 50 => 'ÐÑÔØÄÅÓÑÔ',
  55. 60 => 'ÛÅÓÔØÄÅÓÑÔ',
  56. 70 => 'ÓÅÍØÄÅÓÑÔ',
  57. 80 => '×ÏÓÅÍØÄÅÓÑÔ',
  58. 90 => 'ÄÅ×ÑÎÏÓÔÏ',
  59. 10**2 => 'ÓÔÏ',
  60. 10**3 => 'ÔÙÓÑÞÁ',
  61. 10**6 => 'ÍÉÌÌÉÏÎ',
  62. 10**9 => 'ÍÉÌÌÉÁÒÄ',
  63. 10**12 => 'ÔÒÉÌÌÉÏÎ'
  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 ($i, $appendn);
  74. my @a = ();
  75. while (@num) {
  76. @a = ();
  77. for (1 .. 3) {
  78. push @a, shift @num;
  79. }
  80. push @numblock, join / /, reverse @a;
  81. }
  82. my $belowhundred = !$#numblock;
  83. while (@numblock) {
  84. $i = $#numblock;
  85. @num = split //, $numblock[$i];
  86. $appendn = "";
  87. $numblock[$i] *= 1;
  88. if ($numblock[$i] == 0) {
  89. pop @numblock;
  90. next;
  91. }
  92. if ($numblock[$i] > 99) {
  93. # the one from hundreds
  94. push @textnumber, $self->{numbername}{$num[0]};
  95. # add hundred designation
  96. push @textnumber, $self->{numbername}{10**2};
  97. # reduce numblock
  98. $numblock[$i] -= $num[0] * 100;
  99. }
  100. $appendn = 'en' if ($i == 2);
  101. $appendn = 'n' if ($i > 2);
  102. if ($numblock[$i] > 9) {
  103. # tens
  104. push @textnumber, $self->format_ten($numblock[$i], $belowhundred);
  105. } elsif ($numblock[$i] > 1) {
  106. # ones
  107. push @textnumber, $self->{numbername}{$numblock[$i]};
  108. } elsif ($numblock[$i] == 1) {
  109. if ($i == 0) {
  110. push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
  111. } else {
  112. if ($i >= 2) {
  113. push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
  114. } else {
  115. push @textnumber, $self->{numbername}{$numblock[$i]};
  116. }
  117. }
  118. $appendn = "";
  119. }
  120. # add thousand, million
  121. if ($i) {
  122. $amount = 10**($i * 3);
  123. push @textnumber, $self->{numbername}{$amount}.$appendn;
  124. }
  125. pop @numblock;
  126. }
  127. join '', @textnumber;
  128. }
  129. sub format_ten {
  130. my ($self, $amount, $belowhundred) = @_;
  131. my $textnumber = "";
  132. my @num = split //, $amount;
  133. if ($amount > 20) {
  134. if ($num[1] == 0) {
  135. $textnumber = $self->{numbername}{$amount};
  136. } else {
  137. if ($belowhundred) {
  138. $amount = $num[0] * 10;
  139. $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
  140. } else {
  141. $amount = $num[0] * 10;
  142. $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
  143. $textnumber .= 's' if ($num[1] == 1);
  144. }
  145. }
  146. } else {
  147. $textnumber = $self->{numbername}{$amount};
  148. }
  149. $textnumber;
  150. }
  151. 1;