fork download
  1. <?php
  2.  
  3.  
  4. $word1 = '';
  5. $word2 = '';
  6. $word5 = '';
  7.  
  8. function inclineWord($number) {
  9. $percent = $number % 10;
  10. if($percent == 1){
  11. $word1 = ' рубль';
  12. return $number.$word1;
  13. }
  14. if($percent > 1 and $percent < 5){
  15. $word2 = ' рубля';
  16. return $number.$word2;
  17. }
  18. if($percent > 4 or $percent == 0){
  19. $word5 = ' рублей';
  20. return " (".$number.")".$word5;
  21. }
  22. }
  23.  
  24. function smallNumberToText($number) {
  25.  
  26. $spelling = array(
  27. 0 => 'ноль', 10 => 'десять', 100 => 'сто',
  28. 1 => 'один', 11 => 'одиннадцать', 20 => 'двадцать', 200 => 'двести',
  29. 2 => 'два', 12 => 'двенадцать', 30 => 'тридцать', 300 => 'триста',
  30. 3 => 'три', 13 => 'тринадцать', 40 => 'сорок', 400 => 'четыреста',
  31. 4 => 'четыре', 14 => 'четырнадцать', 50 => 'пятьдесят', 500 => 'пятьсот',
  32. 5 => 'пять', 15 => 'пятнадцать', 60 => 'шестьдесят', 600 => 'шестьсот',
  33. 6 => 'шесть', 16 => 'шестнадцать', 70 => 'семьдесят', 700 => 'семьсот',
  34. 7 => 'семь', 17 => 'семнадцать', 80 => 'восемьдесят', 800 => 'восемьсот',
  35. 8 => 'восемь', 18 => 'восемнадцать', 90 => 'девяносто', 900 => 'девятьсот',
  36. 9 => 'девять', 19 => 'девятнадцать'
  37. );
  38. $text = '';
  39. if($number == 0){
  40. return $spelling[$number];
  41. }
  42. if($number > 0 and $number < 10 or $number > 10 and $number < 20){
  43. return $spelling[$number];
  44. } else {
  45. return $spelling[$number];
  46. }
  47. }
  48. function compilation($number){
  49. return smallNumberToText($number).inclineWord($number);
  50. }
  51. echo compilation(100);
Success #stdin #stdout 0.02s 23532KB
stdin
Standard input is empty
stdout
сто (100) рублей