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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bookDig
Forum Newbie
Posts: 3
Joined: Wed Apr 13, 2016 2:12 pm

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

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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?
Post Reply