Page 1 of 1

setLocal(LC_ALL,"Dutch") a clash expected?

Posted: Fri Apr 15, 2016 5:51 am
by bookDig
Reading the setLocal() fn manual and in comments section I found this
be careful with the LC_ALL setting, as it may introduce some unwanted conversions. For example, I used

setlocale (LC_ALL, "Dutch");

to get my weekdays in dutch on the page. From that moment on (as I found out many hours later) my floating point values from MYSQL where interpreted as integers because the Dutch locale wants a comma (,) instead of a point (.) before the decimals. I tried printf, number_format, floatval.... all to no avail. 1.50 was always printed as 1.00 :(

When I set my locale to :

setlocale (LC_TIME, "Dutch");

my weekdays are good now and my floating point values too.
So my question is does it mean that each locale has its way of treating numbers for example here if a "Dutch" locale is used and it rounds the fraction value from 1.50 to 1.00 because Dutch locale wants a comma (,) instead of a point (.) before the decimals?
By the way isnt the locale short code for dutch is nl_BE, nl_NL, nl maybe its the older version where strings were allowed to be passed instead of one of constant values.

Re: setLocal(LC_ALL,"Dutch") a clash expected?

Posted: Fri Apr 15, 2016 6:53 am
by Celauran
It only affects the display of numbers.
[text]php > $float = 1.50;
php > print_r(setlocale(LC_ALL,0));
C/en_CA.UTF-8/C/C/C/C
php > print $float;
1.5
php > setlocale(LC_MONETARY, 'fr_CA');
php > print $float;
1.5
php > print money_format('%i', $float);
1,50 CAD
php > setlocale(LC_MONETARY, 'en_CA');
php > print $float;
1.5
php > print money_format('%i', $float);
CAD1.50
php > setlocale(LC_NUMERIC, 'fr_CA');
php > print $float;
1,5
php > setlocale(LC_NUMERIC, 'nl_NL');
php > print $float;
1,5
php > setlocale(LC_MONETARY, 'nl_NL');
php > print money_format('%i', $float);
EUR 1,50[/text]
The value of the float hasn't changed. Does that help clarify?