<?php
0 => "миллион",
1 => "миллиона",
2 => "миллионов"
),
0 => "тысяча",
1 => "тысячи",
2 => "тысяч"
),
0 => "рубль",
1 => "рубля",
2 => "рублей"
)
);
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord($declension, $latterFigure, $end) {
if ($latterFigure == 1){
$word = $end[$declension][0];
} elseif (($latterFigure >= 2) && ($latterFigure <= 4)) {
$word = $end[$declension][1];
} else {
$word = $end[$declension][2];
}
return($word);
}
function writeThousand($declension, $discharge, $text, $spelling) {
if (($discharge == 1) && ($declension == 1)) {
$text = $text.' одна';
return($text);
break;
} elseif (($discharge == 2) && ($declension == 1)) {
$text = $text.' две';
return($text);
break;
} else {
$text = $text.' '.$spelling[$discharge];
return($text);
break;
}
}
//разбивает число на миллионы, тысяча и сотни
function splitToParts($number) {
$hundred = $number % 1000;
$thousand = $number % 1000000 * 0.001;
$thousand = floor($thousand);
$million = $number % 1000000000 * 0.000001;
$million = floor ($million);
0 => $million,
1 => $thousand,
2 => $hundred
);
return($level);
}
//переводит числовое число в текстовое
function smallNumberToText($number, $end) {
0 => 'ноль',
1 => 'один',
2 => 'два',
3 => 'три',
4 => 'четыре',
5 => 'пять',
6 => 'шесть',
7 => 'семь',
8 => 'восемь',
9 => 'девять',
10 => 'десять',
11 => 'одиннадцать',
12 => 'двенадцать',
13 => 'тринадцать',
14 => 'четырнадцать',
15 => 'пятнадцать',
16 => 'шестнадцать',
17 => 'семнадцать',
18 => 'восемнадцать',
19 => 'девятнадцать',
20 => 'двадцать',
30 => 'тридцать',
40 => 'сорок',
50 => 'пятьдесят',
60 => 'шестьдесят',
70 => 'семьдесят',
80 => 'восемьдесят',
90 => 'девяносто',
100 => 'сто',
200 => 'двести',
300 => 'триста',
400 => 'четыреста',
500 => 'пятьсот',
600 => 'шестьсот',
700 => 'семьсот',
800 => 'восемьсот',
900 => 'девятьсот',
);
$level = splitToParts($number);
$text = "";
foreach($level as $declension => $discharge) {
if (($discharge % 100 >= 10) && ($discharge % 100 <= 19)) {
$latterFigure = $discharge % 100;
} else {
$latterFigure = $discharge % 10;
}
if ($discharge != 0) {
$aboveZero = true;
}
if (($discharge >= 100) && ($discharge <= 999)) {
$numberInArray = floor($discharge * 0.01) * 100; $text = $text.' '.$spelling[$numberInArray];
$discharge = $discharge % 100;
}
if ($discharge <= 9 || $discharge % 10 == 0) {
$i = 1;
} else {
$i = 2;
}
if (($discharge >= 10) && ($discharge <= 19)) {
$numberInArray = $discharge;
$text = $text.' '.$spelling[$numberInArray];
} elseif ($discharge != 0) {
switch ($i) {
case 1:
$text = writeThousand($declension, $discharge, $text, $spelling);
break;
case 2:
$numberInArray = floor($discharge / 10) * 10; $text = $text.' '.$spelling[$numberInArray];
$discharge = $discharge % 10;
$text = writeThousand($declension, $discharge, $text, $spelling);
break;
}
}
if ($aboveZero == true) {
$word = inclineWord($declension, $latterFigure, $end);
$text = $text.' '.$word;
$aboveZero = false;
}
}
if ($number == 0) {
$text = " ноль рублей";
} elseif ($number % 1000 == 0) {
$text = $text.' '.'рублей';
}
return($text);
}
$number = smallNumberToText($number, $end);
echo "На вашем счету{$number}\n";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRlbmQgPSBhcnJheSgKCTAgPT4gYXJyYXkoCgkJMCA9PiAi0LzQuNC70LvQuNC+0L0iLAoJCTEgPT4gItC80LjQu9C70LjQvtC90LAiLAoJCTIgPT4gItC80LjQu9C70LjQvtC90L7QsiIKCSksCgkxID0+IGFycmF5KAoJCTAgPT4gItGC0YvRgdGP0YfQsCIsCgkJMSA9PiAi0YLRi9GB0Y/Rh9C4IiwKCQkyID0+ICLRgtGL0YHRj9GHIgoJKSwKCTIgPT4gYXJyYXkoCgkJMCA9PiAi0YDRg9Cx0LvRjCIsCgkJMSA9PiAi0YDRg9Cx0LvRjyIsCgkJMiA9PiAi0YDRg9Cx0LvQtdC5IgoJKQopO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ICAgICAgICBicmVhazsKCX0KfQogCi8v0YDQsNC30LHQuNCy0LDQtdGCINGH0LjRgdC70L4g0L3QsCDQvNC40LvQu9C40L7QvdGLLCDRgtGL0YHRj9GH0LAg0Lgg0YHQvtGC0L3QuApmdW5jdGlvbiBzcGxpdFRvUGFydHMoJG51bWJlcikgewoJCgkkaHVuZHJlZCA9ICRudW1iZXIgJSAxMDAwOwogICAKICAgIAogICAgJHRob3VzYW5kID0gJG51bWJlciAlIDEwMDAwMDAgKiAwLjAwMTsKICAgICR0aG91c2FuZCA9IGZsb29yKCR0aG91c2FuZCk7CiAKICAgICRtaWxsaW9uID0gJG51bWJlciAlIDEwMDAwMDAwMDAgKiAwLjAwMDAwMTsKCSRtaWxsaW9uID0gZmxvb3IgKCRtaWxsaW9uKTsKIAoJJGxldmVsID0gYXJyYXkoCgkgICAgMCA9PiAkbWlsbGlvbiwKCQkxID0+ICR0aG91c2FuZCwKCQkyID0+ICRodW5kcmVkCgkpOwoJCglyZXR1cm4oJGxldmVsKTsKfQogCi8v0L/QtdGA0LXQstC+0LTQuNGCINGH0LjRgdC70L7QstC+0LUg0YfQuNGB0LvQviDQsiDRgtC10LrRgdGC0L7QstC+0LUgCmZ1bmN0aW9uIHNtYWxsTnVtYmVyVG9UZXh0KCRudW1iZXIsICRlbmQpIHsKCQogICAgJHNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMCAgID0+ICAn0L3QvtC70YwnLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAxICAgPT4gICfQvtC00LjQvScsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDIgICA9PiAgJ9C00LLQsCcsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDMgICA9PiAgJ9GC0YDQuCcsICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgNCAgID0+ICAn0YfQtdGC0YvRgNC1JywgICAgICAgICAgICAgIAogICAgICAgIDUgICA9PiAgJ9C/0Y/RgtGMJywgICAgICAgICAgICAgICAgCiAgICAgICAgNiAgID0+ICAn0YjQtdGB0YLRjCcsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDcgICA9PiAgJ9GB0LXQvNGMJywgICAgICAgICAgICAgICAgIAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgICAgICAgCiAgICAgICAgOSAgID0+ICAn0LTQtdCy0Y/RgtGMJywKICAgICAgICAxMCAgPT4gICfQtNC10YHRj9GC0YwnLCAJCiAgICAgICAgMTEgID0+ICAn0L7QtNC40L3QvdCw0LTRhtCw0YLRjCcsCQogICAgICAgIDEyICA9PiAgJ9C00LLQtdC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDEzICA9PiAgJ9GC0YDQuNC90LDQtNGG0LDRgtGMJywgCiAgICAgICAgMTQgID0+ICAn0YfQtdGC0YvRgNC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDE1ICA9PiAgJ9C/0Y/RgtC90LDQtNGG0LDRgtGMJywgICAKICAgICAgICAxNiAgPT4gICfRiNC10YHRgtC90LDQtNGG0LDRgtGMJywgCiAgICAgICAgMTcgID0+ICAn0YHQtdC80L3QsNC00YbQsNGC0YwnLCAgCiAgICAgICAgMTggID0+ICAn0LLQvtGB0LXQvNC90LDQtNGG0LDRgtGMJywgICAgCgkgICAgMTkgID0+ICAn0LTQtdCy0Y/RgtC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDIwICA9PiAgJ9C00LLQsNC00YbQsNGC0YwnLCAJCiAgICAgICAgMzAgID0+ICAn0YLRgNC40LTRhtCw0YLRjCcsCiAgICAgICAgNDAgID0+ICAn0YHQvtGA0L7QuicsCiAgICAgICAgNTAgID0+ICAn0L/Rj9GC0YzQtNC10YHRj9GCJywKICAgICAgICA2MCAgPT4gICfRiNC10YHRgtGM0LTQtdGB0Y/RgicsCiAgICAgICAgNzAgID0+ICAn0YHQtdC80YzQtNC10YHRj9GCJywgCiAgICAgICAgODAgID0+ICAn0LLQv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