Edit report at https://bugs.php.net/bug.php?id=54538&edit=1

 ID:                 54538
 Comment by:         hariombalhara at gmail dot com
 Reported by:        davidkarlin at gmail dot com
 Summary:            setlocale() interferes with NumberFormatter class
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   OS X
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

thanks for the workaround. It worked well for me :) Here is the exact problem I 
was facing 
http://stackoverflow.com/questions/16334752/numberformatterformatcurrency-return-
nan-with-fr-fr-utf-8


Previous Comments:
------------------------------------------------------------------------
[2011-07-26 13:01:36] radek dot dvorak at gmail dot com

I have observed a workaround. Setting LC_MESSAGES does not affect 
NumberFormatter
and is sufficient for gettext translations at the same time.

------------------------------------------------------------------------
[2011-04-16 16:52:30] cataphr...@php.net

PHP passes the correct value to ICU, namely it passes the expected double to 
unum_formatDouble. This is likely an ICU defect. See:

http://bugs.icu-project.org/trac/ticket/8214

------------------------------------------------------------------------
[2011-04-15 13:34:02] davidkarlin at gmail dot com

Sorry - I typed the wrong lines in the expected and actual results. Should be 
"123.456,789" in both cases. But you get the idea...

------------------------------------------------------------------------
[2011-04-15 13:32:41] davidkarlin at gmail dot com

Description:
------------
---
>From manual page: http://www.php.net/class.numberformatter
---
When I have my locale set to 'en' with setlocale(), the NumberFormatter class 
works just fine.

If I set the locale to, for example, 'fr_FR', the NumberFormatter class fails, 
giving a 'NaN' result. This is irrespective of the fact that the setlocale() 
function has clearly worked, as evidenced by gettext() working just fine.

I can't see any reason why the setlocale function should have anything to do 
with 
the operation of NumberFormatter: this isn't documented, and I'm explicitly 
passing the locale I want to use in the parameter.

Using 5.3.5 (the most recent available through MacPorts)

Test script:
---------------
setlocale(LC_ALL, 'en');
$nf = new NumberFormatter('de_DE',NumberFormatter::DECIMAL);
print $nf->format(123456.789);  // Outputs the correct answer 123.456,789 
print "<br/>\n";
setlocale(LC_ALL, 'fr_FR');     
$nf = new NumberFormatter('de_DE',NumberFormatter::DECIMAL);
print $nf->format(123456.789); // Outputs NaN

Expected result:
----------------
123456.789<br/>
123456.789

Actual result:
--------------
123456.789<br/>
NaN


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54538&edit=1

Reply via email to