PHP float output format PHP float output format apache apache

PHP float output format


It's because of localization. Since PHP 5.3.0 there is a intl.default_locale option in your php.ini. Should work when you change it to a country, that uses your wanted notation.

Explanation from php.net:

The locale that will be used in intl functions when none is specified (either by >omitting the corresponding argument or by passing NULL). These are ICU locales, not >system locales. The built-in ICU locales and their data can be explored at » >http://demo.icu-project.org/icu-bin/locexp.

The default value is empty, which forces the usage of ICU's default locale. Once set, >the ini setting cannot be reset to this default value. It is not recommended that this >default be relied on, as its effective value depends on the server's environment.

Example for Germany and USA

As you can see under numbers table:

Germany:

Number Pattern: #,##0.### 1.234,56

USA:

Number Pattern: #,##0.### 1,234.56

Edit:

...as its effective value depends on the server's environment.

This means you have to change the local on your server environment. It only uses the set value of php.ini when no server local is set.

For Linux:

If you want to change or set system local, use the update-locale program. The LANG variable allows you to set the locale for the entire system.

The following command sets LANG to en_US.ISO8859-1 and removes definitions for LANGUAGE.

$ sudo update-locale LANG=LANG=en_US.ISO8859-1 LANGUAGEOR$ sudo localectl set-locale LANG=en_US.ISO8859-1

You can find global locale settings in the following files:

  • /etc/default/locale – on Ubuntu/Debian
  • /etc/locale.conf – on CentOS/RHEL


You could use number_format to always keep it clean.

number_format(12.20, 2, '.') : string

for more