Tell me how to output instead of three zeros the word ( thousand ) at the end . For example, if 2000 is displayed, I need to have 2 thousand. But if 15,000, then 15 thousand . Can you tell some function on php.

  • And what to deduce, if 2001? - VladD pm
  • If it prints 2001 then round up to 2 thousand, and if it prints 2100 then 2 thousand 100 - user185447
  • one
    Great, and from what moment stop rounding? - VladD
  • The script should work up to 1 million I apologize, maybe I incorrectly explained - user185447
  • @Muson, meant - how to deduce 2002, 2010, 2099? - aleksandr barakin

3 answers 3

For example:

$summa = 2002; $tys = floor($summa / 1000); $ostatok = $summa % 1000; $itogo = $tys.' тыс. '.$ostatok; 

    The server was not at hand, so on js
    Translate - one minute.

     $('#ok').click(function() { var a = $('#input').val(); var output = ""; if (a == 1000000) { output = '1 млн руб'; } else if (a < 1000) { output = a + 'руб'; } else if (a < 1000000) { output = parseInt(a / 1000) + ' тыс ' + a % 1000 + 'руб'; } else { output = ""; } $('#output').text(output); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="input"> <input type="button" value="ok" id="ok"> <hr> <p id="output"></p> 

    If it is necessary to round, then in the third condition leave only
    output = parseInt(a / 1000) + ' тыс '

      you can start with the number_words package and make the necessary changes to it.

      In debian-core distributions, it is in the php-numbers-words package:

       $ sudo apt-get install php-numbers-words 

      example of one-liner:

       $ php -r 'require_once("Numbers/Words/lang.ru.php"); $obj = new Numbers_Words_ru; print $obj->_toWords(round(999/100)*100) . "\n"; print $obj->_toWords(round(1555/100)*100) . "\n"; print $obj->_toWords(round(1101/100)*100) . "\n";' | iconv -f cp1251 одна тысяча одна тысяча шестьсот одна тысяча сто