I’ve encountered some strange behavior in php, at some point PHP started to output float values with comma instead of dot.
<?php
echo 12.3;
//outputs "12,3" to both browser and CLI
And, as expected, all tracking scripts with float numbers from PHP (prices, QTY etc) are not working now.
Haven’t found any php or apache setting to control that. Has anyone met this before? And maybe knows how to fix/change that?
P.S. Tried setlocale() for LC_ALL and LC_NUMERIC categories, doesn’t work.
2
Answers
You could use
number_format
to always keep it clean.for more
It’s because of localization. Since PHP 5.3.0 there is a
intl.default_locale
option in yourphp.ini
. Should work when you change it to a country, that uses your wanted notation.Explanation from php.net:
Example for Germany and USA
As you can see under numbers table:
Germany:
USA:
Edit:
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. TheLANG
variable allows you to set the locale for the entire system.The following command sets
LANG
toen_US.ISO8859-1
and removes definitions forLANGUAGE
.You can find global locale settings in the following files:
/etc/default/locale
โ on Ubuntu/Debian/etc/locale.conf
โ on CentOS/RHEL