$text= (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => '11.101']); //выведет: одиннадцать целых сто одна тысячная $text= (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => '11.100']); //выведет: одиннадцать целых одна десятая 

How to make eleven point one hundred thousandth?

  • Can learn mathematics, where did you see the number 11.100 (eleven whole, one hundred thousandths)? or work with a string. By the way the question is very interesting where did you see such a number? - Naumov
  • did not understand what it means to work with a string? Percentages up to the thousandth are asked to be output by the text, although there are only tenths always. - Alex Semenov
  • in principle, came up with an option, cut the tenth with hands and substitute thousandths, but this is a perversion of course - Alex Semenov
  • The fact is that in nature there is no number 11.100, so here it is only to work with the “number” as with a string. - Naumov
  • it was needed in the contract in microfinance, they say it is so necessary by law - Alex Semenov

2 answers 2

solved the problem so maybe someone come in handy

  $percents_year = "40.4"; $number = sprintf('%.3f', $percents_year); $res = explode('.', floatval($number)); $num = $res[0]; $dec = isset($res[1]) ? $res[1] : 0; $res = explode('.',$number); $decStr = isset($res[1]) ? $res[1] : 0; if (floatval($dec) < 100) { $first = (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => $num]); $secont = (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => $decStr]); $resText = $first . ' целых ' . $secont . ' тысячных'; } else { $resText = (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => $number]); } $percents_year_text = $resText; 

    Firstly, such numbers exist in mathematics, too - and this is called accuracy of the number up to the thousandth. I can offer you the following solution

    1. Inherit the MessageFormatter class

    2. Use Polymorphism subclass like this

      class MyMessageFormatter extends MessageFormatter {public function format ($ arr) {// rewrite to fit your logic}}

      $ text = (new \ MyMessageFormatter ('en-RU', '{n, spellout}')) -> format (['n' => '11 .100 ']);

    • If it were still possible to look somewhere the source code of the format method, then in general it would be great - Alex Semenov
    • well, that's easy. For example, in Notepad ++ there is a search in files Ctrl + Shift + f for this you need to download the files on your computer and run a search in these files for example public function format - Mcile
    • intl is installed as a php library, so I don’t see the logic of the method - Alex Semenov
    • Link to the article where it is proved, or to school again. - Naumov