summaryrefslogtreecommitdiff
path: root/LedgerSMB/Num2text.pm
blob: 39930fc5961b35f0a1b7e16f82efab9f2281ec1a (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. # Copyright (C) 2006
  7. # This work contains copyrighted information from a number of sources all used
  8. # with permission.
  9. #
  10. # This file contains source code included with or based on SQL-Ledger which
  11. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  12. # under the GNU General Public License version 2 or, at your option, any later
  13. # version. For a full list including contact information of contributors,
  14. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  15. #
  16. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  17. # Copyright (C) 2002
  18. #
  19. # Author: DWS Systems Inc.
  20. # Web: http://www.sql-ledger.org
  21. #
  22. # Contributors:
  23. #
  24. #======================================================================
  25. #
  26. # This file has NOT undergone whitespace cleanup.
  27. #
  28. #======================================================================
  29. #
  30. # this is the default code for the Check package
  31. #
  32. #=====================================================================
  33. sub init {
  34. my $self = shift;
  35. my $locale = $self->{'locale'};
  36. my $langtag = substr($locale->language_tag, 0, 2);
  37. $self->{'numrules'} = 'en';
  38. $self->{'numrules'} = $langtag if
  39. grep {/$langtag/} (qw/ca de es et fr hu it nl ru/);
  40. $self->{'numrules'} = 'es' if $self->{'numrules'} eq 'ca';
  41. $self->{'numrules'} = 'de' if $self->{'numrules'} eq 'ru';
  42. %{ $self->{numbername} } =
  43. (0 => $locale->text('Zero'),
  44. 1 => $locale->text('One'),
  45. 2 => $locale->text('Two'),
  46. 3 => $locale->text('Three'),
  47. 4 => $locale->text('Four'),
  48. 5 => $locale->text('Five'),
  49. 6 => $locale->text('Six'),
  50. 7 => $locale->text('Seven'),
  51. 8 => $locale->text('Eight'),
  52. 9 => $locale->text('Nine'),
  53. 10 => $locale->text('Ten'),
  54. 11 => $locale->text('Eleven'),
  55. 12 => $locale->text('Twelve'),
  56. 13 => $locale->text('Thirteen'),
  57. 14 => $locale->text('Fourteen'),
  58. 15 => $locale->text('Fifteen'),
  59. 16 => $locale->text('Sixteen'),
  60. 17 => $locale->text('Seventeen'),
  61. 18 => $locale->text('Eighteen'),
  62. 19 => $locale->text('Nineteen'),
  63. 20 => $locale->text('Twenty'),
  64. 21 => $locale->text('Twenty One'),
  65. 22 => $locale->text('Twenty Two'),
  66. 23 => $locale->text('Twenty Three'),
  67. 24 => $locale->text('Twenty Four'),
  68. 25 => $locale->text('Twenty Five'),
  69. 26 => $locale->text('Twenty Six'),
  70. 27 => $locale->text('Twenty Seven'),
  71. 28 => $locale->text('Twenty Eight'),
  72. 29 => $locale->text('Twenty Nine'),
  73. 30 => $locale->text('Thirty'),
  74. 40 => $locale->text('Forty'),
  75. 50 => $locale->text('Fifty'),
  76. 60 => $locale->text('Sixty'),
  77. 70 => $locale->text('Seventy'),
  78. 80 => $locale->text('Eighty'),
  79. 90 => $locale->text('Ninety'),
  80. 10**2 => $locale->text('Hundred'),
  81. 500 => $locale->text('Five Hundred'),
  82. 700 => $locale->text('Seven Hundred'),
  83. 900 => $locale->text('Nine Hundred'),
  84. 10**3 => $locale->text('Thousand'),
  85. 10**6 => $locale->text('Million'),
  86. 10**9 => $locale->text('Billion'),
  87. 10**12 => $locale->text('Trillion'),
  88. );
  89. }
  90. sub num2text {
  91. my ($self, $amount) = @_;
  92. return $self->num2text_de($amount) if $self->{'numrules'} eq 'de';
  93. return $self->num2text_es($amount) if $self->{'numrules'} eq 'es';
  94. return $self->num2text_nl($amount) if $self->{'numrules'} eq 'nl';
  95. return $self->num2text_hu($amount) if $self->{'numrules'} eq 'hu';
  96. return $self->num2text_et($amount) if $self->{'numrules'} eq 'et';
  97. return $self->num2text_fr($amount) if $self->{'numrules'} eq 'fr';
  98. return $self->num2text_it($amount) if $self->{'numrules'} eq 'it';
  99. return $self->num2text_en($amount);
  100. }
  101. sub num2text_en {
  102. my ($self, $amount) = @_;
  103. return $self->{numbername}{0} unless $amount;
  104. my @textnumber = ();
  105. # split amount into chunks of 3
  106. my @num = reverse split //, abs($amount);
  107. my @numblock = ();
  108. my @a;
  109. my $i;
  110. while (@num) {
  111. @a = ();
  112. for (1 .. 3) {
  113. push @a, shift @num;
  114. }
  115. push @numblock, join / /, reverse @a;
  116. }
  117. while (@numblock) {
  118. $i = $#numblock;
  119. @num = split //, $numblock[$i];
  120. if ($numblock[$i] == 0) {
  121. pop @numblock;
  122. next;
  123. }
  124. if ($numblock[$i] > 99) {
  125. # the one from hundreds
  126. push @textnumber, $self->{numbername}{$num[0]};
  127. # add hundred designation
  128. push @textnumber, $self->{numbername}{10**2};
  129. # reduce numblock
  130. $numblock[$i] -= $num[0] * 100;
  131. }
  132. $numblock[$i] *= 1;
  133. if ($numblock[$i] > 9) {
  134. # tens
  135. push @textnumber, $self->format_ten_en($numblock[$i]);
  136. } elsif ($numblock[$i] > 0) {
  137. # ones
  138. push @textnumber, $self->{numbername}{$numblock[$i]};
  139. }
  140. # add thousand, million
  141. if ($i) {
  142. $num = 10**($i * 3);
  143. push @textnumber, $self->{numbername}{$num};
  144. }
  145. pop @numblock;
  146. }
  147. join ' ', @textnumber;
  148. }
  149. sub format_ten_en {
  150. my ($self, $amount) = @_;
  151. my $textnumber = "";
  152. my @num = split //, $amount;
  153. if ($amount > 20) {
  154. $textnumber = $self->{numbername}{$num[0]*10};
  155. $amount = $num[1];
  156. } else {
  157. $textnumber = $self->{numbername}{$amount};
  158. $amount = 0;
  159. }
  160. $textnumber .= " ".$self->{numbername}{$amount} if $amount;
  161. $textnumber;
  162. }
  163. sub num2text_de {
  164. my ($self, $amount) = @_;
  165. return $self->{numbername}{0} unless $amount;
  166. my @textnumber = ();
  167. # split amount into chunks of 3
  168. my @num = reverse split //, abs($amount);
  169. my @numblock = ();
  170. my ($i, $appendn);
  171. my @a = ();
  172. while (@num) {
  173. @a = ();
  174. for (1 .. 3) {
  175. push @a, shift @num;
  176. }
  177. push @numblock, join / /, reverse @a;
  178. }
  179. my $belowhundred = !$#numblock;
  180. while (@numblock) {
  181. $i = $#numblock;
  182. @num = split //, $numblock[$i];
  183. $appendn = "";
  184. $numblock[$i] *= 1;
  185. if ($numblock[$i] == 0) {
  186. pop @numblock;
  187. next;
  188. }
  189. if ($numblock[$i] > 99) {
  190. # the one from hundreds
  191. push @textnumber, $self->{numbername}{$num[0]};
  192. # add hundred designation
  193. push @textnumber, $self->{numbername}{10**2};
  194. # reduce numblock
  195. $numblock[$i] -= $num[0] * 100;
  196. }
  197. $appendn = 'en' if ($i == 2);
  198. $appendn = 'n' if ($i > 2);
  199. if ($numblock[$i] > 9) {
  200. # tens
  201. push @textnumber, $self->format_ten_de($numblock[$i], $belowhundred);
  202. } elsif ($numblock[$i] > 1) {
  203. # ones
  204. push @textnumber, $self->{numbername}{$numblock[$i]};
  205. } elsif ($numblock[$i] == 1) {
  206. if ($i == 0) {
  207. push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
  208. } else {
  209. if ($i >= 2) {
  210. push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
  211. } else {
  212. push @textnumber, $self->{numbername}{$numblock[$i]};
  213. }
  214. }
  215. $appendn = "";
  216. }
  217. # add thousand, million
  218. if ($i) {
  219. $amount = 10**($i * 3);
  220. push @textnumber, $self->{numbername}{$amount}.$appendn;
  221. }
  222. pop @numblock;
  223. }
  224. join '', @textnumber;
  225. }
  226. sub format_ten_de {
  227. my ($self, $amount, $belowhundred) = @_;
  228. my $textnumber = "";
  229. my @num = split //, $amount;
  230. if ($amount > 20) {
  231. if ($num[1] == 0) {
  232. $textnumber = $self->{numbername}{$amount};
  233. } else {
  234. if ($belowhundred) {
  235. $amount = $num[0] * 10;
  236. $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
  237. } else {
  238. $amount = $num[0] * 10;
  239. $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
  240. $textnumber .= 's' if ($num[1] == 1);
  241. }
  242. }
  243. } else {
  244. $textnumber = $self->{numbername}{$amount};
  245. }
  246. $textnumber;
  247. }
  248. sub num2text_et {
  249. my ($self, $amount) = @_;
  250. return $self->{numbername}{0} unless $amount;
  251. my @textnumber = ();
  252. # split amount into chunks of 3
  253. my @num = reverse split //, abs($amount);
  254. my @numblock = ();
  255. my ($i, $appendit);
  256. my @a = ();
  257. while (@num) {
  258. @a = ();
  259. for (1 .. 3) {
  260. push @a, shift @num;
  261. }
  262. push @numblock, join / /, reverse @a;
  263. }
  264. while (@numblock) {
  265. $i = $#numblock;
  266. $numblock[$i] *= 1;
  267. @num = split //, $numblock[$i];
  268. $appendit = "it";
  269. $hundred = 0;
  270. if ($numblock[$i] == 0) {
  271. pop @numblock;
  272. next;
  273. }
  274. if ($numblock[$i] > 99) {
  275. # the one from hundreds
  276. push @textnumber, "$self->{numbername}{$num[0]}$self->{numbername}{10**2}";
  277. # reduce numblock
  278. $numblock[$i] -= $num[0] * 100;
  279. @num = split //, $numblock[$i];
  280. $hundred = 1;
  281. }
  282. if ($numblock[$i] > 19) {
  283. # 20 - 99
  284. push @textnumber, "$self->{numbername}{$num[0]}kümmend";
  285. @num = split //, $numblock[$i];
  286. push @textnumber, $self->{numbername}{$num[1]} if $num[1] > 0;
  287. } elsif ($numblock[$i] > 10) {
  288. # 11 - 19
  289. if ($hundred) {
  290. @num = split //, $numblock[$i];
  291. }
  292. $num = $num[1];
  293. push @textnumber, "$self->{numbername}{$num}teist";
  294. } elsif ($numblock[$i] > 1) {
  295. # ones
  296. push @textnumber, $self->{numbername}{$numblock[$i]};
  297. } elsif ($numblock[$i] == 1) {
  298. push @textnumber, $self->{numbername}{$num[0]};
  299. $appendit = "";
  300. }
  301. # add thousand, million
  302. if ($i) {
  303. $amount = 10**($i * 3);
  304. $appendit = ($i == 1) ? "" : $appendit;
  305. push @textnumber, "$self->{numbername}{$amount}$appendit";
  306. }
  307. pop @numblock;
  308. }
  309. join ' ', @textnumber;
  310. }
  311. sub num2text_es {
  312. my ($self, $amount) = @_;
  313. return $self->{numbername}{0} unless $amount;
  314. my @textnumber = ();
  315. # split amount into chunks of 3
  316. my @num = reverse split //, abs($amount);
  317. my @numblock = ();
  318. my $stripun = 0;
  319. my @a = ();
  320. my $i;
  321. while (@num) {
  322. @a = ();
  323. for (1 .. 3) {
  324. push @a, shift @num;
  325. }
  326. push @numblock, join / /, reverse @a;
  327. }
  328. # special case for 1000
  329. if ($numblock[1] eq '1' && $numblock[0] gt '000') {
  330. # remove first array element from textnumber
  331. $stripun = 1;
  332. }
  333. while (@numblock) {
  334. $i = $#numblock;
  335. @num = split //, $numblock[$i];
  336. $numblock[$i] *= 1;
  337. if ($numblock[$i] == 0) {
  338. pop @numblock;
  339. next;
  340. }
  341. if ($numblock[$i] > 99) {
  342. if ($num[0] == 1) {
  343. push @textnumber, $self->{numbername}{10**2};
  344. } else {
  345. # special case for 500, 700, 900
  346. if (grep /$num[0]/, (5,7,9)) {
  347. push @textnumber, $self->{numbername}{"${num[0]}00"};
  348. } else {
  349. # the one from hundreds, append cientos
  350. push @textnumber, $self->{numbername}{$num[0]}.$self->{numbername}{10**2}.'s';
  351. }
  352. }
  353. # reduce numblock
  354. $numblock[$i] -= $num[0] * 100;
  355. }
  356. if ($numblock[$i] > 9) {
  357. # tens
  358. push @textnumber, $self->format_ten_es($numblock[$i], $i);
  359. } elsif ($numblock[$i] > 0) {
  360. # ones
  361. $num = $numblock[$i];
  362. $num .= 'o' if ($num == 1 && $i == 0);
  363. push @textnumber, $self->{numbername}{$num};
  364. }
  365. # add thousand, million
  366. if ($i) {
  367. $num = 10**($i * 3);
  368. if ($numblock[$i] > 1) {
  369. if ($i == 2 || $i == 4) {
  370. $a = $self->{numbername}{$num}."es";
  371. $a =~ s/ó/o/;
  372. push @textnumber, $a;
  373. } elsif ($i == 3) {
  374. $num = 10**($i * 2);
  375. $a = "$self->{10**3} $self->{numbername}{$num}"."es";
  376. $a =~ s/ó/o/;
  377. push @textnumber, $a;
  378. } else {
  379. if ($i == 1) {
  380. push @textnumber, $self->{numbername}{$num};
  381. } else {
  382. push @textnumber, $self->{numbername}{$num}.'s';
  383. }
  384. }
  385. } else {
  386. push @textnumber, $self->{numbername}{$num};
  387. }
  388. }
  389. pop @numblock;
  390. }
  391. shift @textnumber if $stripun;
  392. join ' ', @textnumber;
  393. }
  394. sub format_ten_es {
  395. my ($self, $amount, $i) = @_;
  396. my $textnumber = "";
  397. my @num = split //, $amount;
  398. if ($amount > 30) {
  399. $textnumber = $self->{numbername}{$num[0]*10};
  400. $amount = $num[1];
  401. } else {
  402. $amount .= 'o' if ($num[1] == 1 && $i == 0);
  403. $textnumber = $self->{numbername}{$amount};
  404. $amount = 0;
  405. }
  406. $textnumber .= " y ".$self->{numbername}{$amount} if $amount;
  407. $textnumber;
  408. }
  409. sub num2text_fr {
  410. my ($self, $amount) = @_;
  411. return $self->{numbername}{0} unless $amount;
  412. my @textnumber = ();
  413. # split amount into chunks of 3
  414. my @num = reverse split //, abs($amount);
  415. my @numblock = ();
  416. my @a;
  417. my $i;
  418. while (@num) {
  419. @a = ();
  420. for (1 .. 3) {
  421. push @a, shift @num;
  422. }
  423. push @numblock, join / /, reverse @a;
  424. }
  425. my $cent=0;
  426. while (@numblock) {
  427. $i = $#numblock;
  428. @num = split //, $numblock[$i];
  429. if ($numblock[$i] == 0) {
  430. pop @numblock;
  431. next;
  432. }
  433. if ($numblock[$i] > 99) {
  434. $cent=1;
  435. # the one from hundreds
  436. if ($num[0] > 1) {
  437. push @textnumber, $self->{numbername}{$num[0]};
  438. }
  439. # reduce numblock
  440. $numblock[$i] -= $num[0] * 100;
  441. # add hundred designation
  442. if ($num[0] > 1) {
  443. if($numblock[$i] > 0) {
  444. push @textnumber, $self->{numbername}{10**2};
  445. } else {
  446. push @textnumber, "$self->{numbername}{10**2}s";
  447. }
  448. } else {
  449. push @textnumber, $self->{numbername}{10**2};
  450. }
  451. }
  452. $numblock[$i] *= 1;
  453. if ($numblock[$i] > 9) {
  454. # tens
  455. push @textnumber, $self->format_ten_fr($numblock[$i]);
  456. } elsif ($numblock[$i] > 0) {
  457. # ones
  458. if ($i == 1) {
  459. if ($cent == 1) {
  460. push @textnumber, $self->{numbername}{$numblock[$i]};
  461. }
  462. $cent = 0;
  463. } else {
  464. push @textnumber, $self->{numbername}{$numblock[$i]};
  465. }
  466. }
  467. # add thousand, million
  468. if ($i) {
  469. $num = 10**($i * 3);
  470. if ($i == 1) {
  471. push @textnumber, $self->{numbername}{$num};
  472. } elsif ($numblock[$i] > 1) {
  473. push @textnumber, "$self->{numbername}{$num}s";
  474. } else {
  475. push @textnumber, "$self->{numbername}{$num}";
  476. }
  477. }
  478. pop @numblock;
  479. }
  480. join ' ', @textnumber;
  481. }
  482. sub format_ten_fr {
  483. my ($self, $amount) = @_;
  484. my $textnumber = "";
  485. my @num = split //, $amount;
  486. if ($amount > 20) {
  487. if ($num[0] == 8) {
  488. if ($num[1] > 0) {
  489. $textnumber = $self->{numbername}{$num[0]*10};
  490. } else {
  491. $textnumber = "$self->{numbername}{$num[0]*10}s";
  492. }
  493. $amount = $num[1];
  494. } elsif ($num[0] == 7 || $num[0] == 9) {
  495. if ($num[1] > 0) {
  496. $textnumber = $self->{numbername}{($num[0]-1)*10};
  497. $textnumber .= " et" if ($num[1] == 1 && $num[0] == 7);
  498. $amount -= ($num[0]-1)*10;
  499. } else {
  500. $textnumber = $self->{numbername}{$num[0]*10};
  501. $amount = $num[1];
  502. }
  503. } else {
  504. $textnumber = $self->{numbername}{$num[0]*10};
  505. $textnumber .= " et" if ($num[1] == 1);
  506. $amount = $num[1];
  507. }
  508. } else {
  509. $textnumber = "$self->{numbername}{$amount}";
  510. $amount = 0;
  511. }
  512. $textnumber .= " ".$self->{numbername}{$amount} if $amount;
  513. $textnumber;
  514. }
  515. sub num2text_hu {
  516. my ($self, $amount) = @_;
  517. return $self->{numbername}{0} unless $amount;
  518. my @textnumber = ();
  519. # split amount into chunks of 3
  520. my @num = reverse split //, abs($amount);
  521. my @numblock = ();
  522. my @a;
  523. my $i;
  524. my $res;
  525. while (@num) {
  526. @a = ();
  527. for (1 .. 3) {
  528. push @a, shift @num;
  529. }
  530. push @numblock, join / /, reverse @a;
  531. }
  532. while (@numblock) {
  533. $i = $#numblock;
  534. @num = split //, $numblock[$i];
  535. if ($numblock[$i] == 0) {
  536. pop @numblock;
  537. next;
  538. }
  539. if ($numblock[$i] > 99) {
  540. push @textnumber, $self->{numbername}{$num[0]};
  541. # add hundred designation
  542. push @textnumber, $self->{numbername}{10**2};
  543. # reduce numblock
  544. $numblock[$i] -= $num[0] * 100;
  545. }
  546. $numblock[$i] *= 1;
  547. if ($numblock[$i] > 9) {
  548. # tens
  549. push @textnumber, $self->format_ten_hu($numblock[$i]);
  550. } elsif ($numblock[$i] > 0) {
  551. # ones
  552. push @textnumber, $self->{numbername}{$numblock[$i]};
  553. }
  554. # add thousand, million
  555. if ($i) {
  556. if ($i==1 && $amount < 2000){
  557. $num = 10**($i * 3);
  558. push @textnumber, $self->{numbername}{$num};
  559. } else {
  560. $num = 10**($i * 3);
  561. push @textnumber, $self->{numbername}{$num}."-";
  562. }
  563. }
  564. pop @numblock;
  565. }
  566. $res=ucfirst join '', @textnumber;
  567. $res=~s/(\-)$//;
  568. return $res;
  569. }
  570. sub format_ten_hu {
  571. my ($self, $amount) = @_;
  572. my $textnumber = "";
  573. my @num = split //, $amount;
  574. if ($amount > 30) {
  575. $textnumber = $self->{numbername}{$num[0]*10};
  576. $amount = $num[1];
  577. } else {
  578. $textnumber = $self->{numbername}{$amount};
  579. $amount = 0;
  580. }
  581. $textnumber .= "".$self->{numbername}{$amount} if $amount;
  582. $textnumber;
  583. }
  584. sub num2text_nl {
  585. my ($self, $amount) = @_;
  586. return $self->{numbername}{0} unless $amount;
  587. my @textnumber = ('**');
  588. # split amount into chunks of 3
  589. my @num = reverse split //, abs($amount);
  590. my @numblock = ();
  591. my ($i, $appendn);
  592. my @a = ();
  593. while (@num) {
  594. @a = ();
  595. for (1 .. 3) {
  596. push @a, shift @num;
  597. }
  598. push @numblock, join / /, reverse @a;
  599. }
  600. while (@numblock) {
  601. $i = $#numblock;
  602. @num = split //, $numblock[$i];
  603. $numblock[$i] *= 1;
  604. if ($numblock[$i] == 0) {
  605. pop @numblock;
  606. next;
  607. }
  608. if ($numblock[$i] > 99) {
  609. # the one from hundreds
  610. push @textnumber, $self->{numbername}{$num[0]};
  611. # add hundred designation
  612. push @textnumber, $self->{numbername}{10**2};
  613. # reduce numblock
  614. $numblock[$i] -= $num[0] * 100;
  615. }
  616. if ($numblock[$i] > 9) {
  617. # tens
  618. push @textnumber, $self->format_ten_nl($numblock[$i]);
  619. } else {
  620. # ones
  621. push @textnumber, $self->{numbername}{$numblock[$i]};
  622. }
  623. # add thousand, million
  624. if ($i) {
  625. $amount = 10**($i * 3);
  626. push @textnumber, $self->{numbername}{$amount};
  627. }
  628. pop @numblock;
  629. }
  630. push @textnumber, '**';
  631. join '', @textnumber;
  632. }
  633. sub format_ten_nl {
  634. my ($self, $amount) = @_;
  635. my $textnumber = "";
  636. my @num = split //, $amount;
  637. if ($amount > 20) {
  638. # reverse one and ten and glue together with 'en'
  639. $amount = $num[0] * 10;
  640. $textnumber = $self->{numbername}{$num[1]}.'en'.$self->{numbername}{$amount};
  641. } else {
  642. $textnumber = $self->{numbername}{$amount};
  643. }
  644. $textnumber;
  645. }
  646. sub num2text_it {
  647. my ($self, $amount) = @_;
  648. return $self->{numbername}{0} unless $amount;
  649. my @textnumber = ();
  650. # split amount into chunks of 3
  651. my @num = reverse split //, abs($amount);
  652. my @numblock = ();
  653. my ($i, $appendn);
  654. my @a = ();
  655. while (@num) {
  656. @a = ();
  657. for (1 .. 3) {
  658. push @a, shift @num;
  659. }
  660. push @numblock, join / /, reverse @a;
  661. }
  662. while (@numblock) {
  663. $i = $#numblock;
  664. @num = split //, $numblock[$i];
  665. $numblock[$i] *= 1;
  666. if ($numblock[$i] == 0) {
  667. pop @numblock;
  668. next;
  669. }
  670. if ($numblock[$i] > 99) {
  671. # the one from hundreds
  672. push @textnumber, $self->{numbername}{$num[0]};
  673. # add hundred designation
  674. push @textnumber, $self->{numbername}{10**2};
  675. # reduce numblock
  676. $numblock[$i] -= $num[0] * 100;
  677. }
  678. if ($numblock[$i] > 9) {
  679. # tens
  680. push @textnumber, $self->format_ten_it($numblock[$i]);
  681. } elsif ($numblock[$i] > 1) {
  682. # ones
  683. push @textnumber, $self->{numbername}{$numblock[$i]};
  684. }
  685. # add thousand, million
  686. if ($i) {
  687. $amount = 10**($i * 3);
  688. push @textnumber, $self->{numbername}{$amount};
  689. }
  690. pop @numblock;
  691. }
  692. join '', @textnumber;
  693. }
  694. sub format_ten_it {
  695. my ($self, $amount) = @_;
  696. my $textnumber = "";
  697. my @num = split //, $amount;
  698. if ($amount > 20) {
  699. if ($num[1] == 0) {
  700. $textnumber = $self->{numbername}{$amount};
  701. } else {
  702. $amount = $num[0] * 10;
  703. $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
  704. }
  705. } else {
  706. $textnumber = $self->{numbername}{$amount};
  707. }
  708. $textnumber;
  709. }
  710. 1;