php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39873 thousands_sep not shown
Submitted: 2006-12-18 17:48 UTC Modified: 2006-12-22 04:03 UTC
From: rob4you at vodafone dot it Assigned:
Status: Closed Package: Strings related
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
 [2006-12-18 17:48 UTC] rob4you at vodafone dot it
Description:
------------
The [thousands_sep] states dot "." as separator of thousands, but the output of the number DOES NOT show it. 
It is correctly shown in the array returned by "localeconv" although.
I've observed the same problem on other OS and with other locales.

Reproduce code:
---------------
<?php
echo "<pre>";
$ita=array("ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1");
$local_settings=setlocale(LC_ALL,$ita);
echo $local_settings."<br>";

$num=0+"1234.56";  

echo $num;
printf("\n Not dependant in local settings: %F \n",$num);
printf("\n Dependant on local settings: %f \n",$num);

$x=localeconv();
print_r($x);
echo "</pre>";
?>

Expected result:
----------------
Italian_Italy.1252
1.234,56
 Not dependant in local settings: 1234.560000 

 Dependant on local settings: 1.234,560000 
Array
(
    [decimal_point] => ,
    [thousands_sep] => .

    ...etc...

)

Actual result:
--------------
Italian_Italy.1252
1234,56
 Not dependant in local settings: 1234.560000 

 Dependant on local settings: 1234,560000 
Array
(
    [decimal_point] => ,
    [thousands_sep] => .

    ...etc...

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-18 18:52 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-12-18 19:43 UTC] rob4you at vodafone dot it
I've tried the link for Windows you suggested: http://snaps.php.net/win32/php5.2-win32-latest.zip.
Now i've this version of php: "PHP Version 5.2.1RC2-dev".

But the problem isn't resolved. On the contrary, it's going worse: now it's ignored also the decimal separator [decimal_point] with %f.
The problem persists also with other os.
With the same script of the previous message, here it is the output produced:

Actual result:
--------------
Italian_Italy.1252
1234,56
 Not dependant in local settings: 1234.56000 

 Dependant on local settings: 1234.560000 
Array
(
    [decimal_point] => ,
    [thousands_sep] => .

    ...etc...

)

The expected result is obviously the same as the previous message:
Expected result:
----------------
Italian_Italy.1252
1.234,56
 Not dependant in local settings: 1234.560000 

 Dependant on local settings: 1.234,560000 
Array
(
    [decimal_point] => ,
    [thousands_sep] => .

    ...etc...

)
 [2006-12-19 15:07 UTC] tony2001@php.net
>But the problem isn't resolved. 
Yes, it was never supposed to work this way.
This is exactly the reason why wer have number_format() function.

>On the contrary, it's going worse:
I can't reproduce this.
Please try the next snapshot.
 [2006-12-19 15:21 UTC] rob4you at vodafone dot it
> Yes, it was never supposed to work this way.
> This is exactly the reason why wer have number_format() 
> function.

I don't think so.
If I see, in localeconv():
    [decimal_point] => ,
    [thousands_sep] => .

I expect that the number formatted with:
printf("%f",$num)

is 1.234,56 and NOT 1234,56

As you can see the [decimal_point] is ",", according with localeconv(), but the [thousands_sep] doesn't appear here, disaccording with localeconv().

The manual states about the %f:
"f - the argument is treated as a float, and presented as a floating-point number (locale aware)."

But in this case the locale aware is not respected: it's respected only for [decimal_point] and NOT for [thousands_sep].

>> On the contrary, it's going worse:
> I can't reproduce this.
> Please try the next snapshot.

For:
printf("%f",$num)
before it produced (with loca setted on "it"):
"1234,56"
now it incorrectly produces:
"1234.56"
that is it forgets both the [thousands_sep] AND the [decimal_point].
 [2006-12-19 15:31 UTC] tony2001@php.net
>I don't think so.
>If I see, in localeconv():
>I expect that the number formatted with:

That does not mean it was supposed to work the way you expect.

>But in this case the locale aware is not respected: it's
> respected only for [decimal_point] and NOT for
> [thousands_sep].
Right, that's how it is supposed to work and it should be clarified in the docs.

>now it incorrectly produces:
Again, please try the NEXT snapshot, I'm unableto reproduce it.
 [2006-12-19 16:30 UTC] rob4you at vodafone dot it
> That does not mean it was supposed to work the way you 
> expect.
> it should be clarified in the docs.

Yes, if this is the way it works, it should be clarified in docs.

> please try the NEXT snapshot, I'm unableto reproduce it.

I've tried the last available snapshot. 
Here is the problem:

Reproduce code:
---------------
<?php
$ita=array("ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1");
setlocale(LC_ALL,$ita);

$num=0+"1234.56";  

$formatted_num=number_format($num,2);
echo $formatted_num;
?>

Expected result:
----------------
1,234.56

Actual result:
--------------
1,234,,56.00

it sounds quite strange...:-)
 [2006-12-22 04:03 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC