PHP money_format not working

I am using Laravel 4 on TurnkeyLinux and trying to get money_format to display currency in a localized way.

money_format('%.2n', 1222002.09) returns 1222002.09.

In app / strart / global.php, I have App::setLocale(Session::get('locale', 'en')); , this changes the language using Laravel language files, but does not affect the currency.

I found that localeconv(); displays an almost empty array (only a decimal point is set), and use setLocale(LC_ALL, 'en_GB', 'en_GB'); has no effect.

I am on PHP 5.4.4 and Debian 3.2.57.

+6
source share
1 answer

Got! Thanks to Dmitry Bezik for pointing me in the right direction.

locale -a :

  • WITH
  • C.UTF-8
  • Posix

The lack of local GBs (or the USA) prompted me to do another search, which found me this page .

Basically, I didn’t have the locales installed, so I followed the instructions and set the GB locale by doing the following:

  • I opened /etc/locale.gen using WinSCP and scrolled through the list of localized locales until I found en_GB.UTF-8 UTF-8 and deleted the leading "#" (if your file is empty, you just need to add an entry).
  • Ran /usr/sbin/locale-gen as root, this made the "Generate locales" system (which took only a second).
  • Added setLocale(LC_ALL, 'en_GB.utf8', 'en_GB'); into my clip template and updated.

Voila! Now I get £1,222,002.09 .
Then I moved my setLocale code to my /start/global.php application right after I installed the language so that it runs on every request.

+7
source

Source: https://habr.com/ru/post/974069/


All Articles