php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58325 NumberFormatter double parsing breaks when locale changes
Submitted: 2008-08-25 14:57 UTC Modified: 2009-01-30 15:59 UTC
From: bjoernhaeuser at gmail dot com Assigned:
Status: Closed Package: intl (PECL)
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 + 44 = ?
Subscribe to this entry?

 
 [2008-08-25 14:57 UTC] bjoernhaeuser at gmail dot com
Description:
------------
It seems that the NumberFormatter is not able to parse its own Output. 

Reproduce code:
---------------
<?php

/*

# locale -a | grep de_DE
de_DE.ISO8859-1
de_DE.ISO8859-15
de_DE.UTF-8

*/
/* ########################### */

$en_locale="en_US.UTF-8";
$de_locale="de_DE.UTF-8";

/* ########################### */

echo setlocale(LC_ALL, $en_locale) . '<br/>';
$fmt = new NumberFormatter($en_locale, NumberFormatter::DEFAULT_STYLE );

$string  = $fmt->format(1234.56);
$numeric = $fmt->parse($string);

var_dump($string);
echo '<br/>';
var_dump($numeric);

echo '<br/>';
echo setlocale(LC_ALL, $de_locale) . '<br/>';
$fmt = new NumberFormatter($de_locale,  NumberFormatter::DEFAULT_STYLE);

$string  = $fmt->format(1234.56);
$numeric = $fmt->parse($string);

var_dump($string);
echo '<br/>';
var_dump($numeric);

highlight_file(__FILE__);

?>

Expected result:
----------------
en_US.UTF-8
string(8) "1,234.56"
float(1234.56)
de_DE.UTF-8
string(8) "1.234,56"
float(1234.56)

Actual result:
--------------
en_US.UTF-8
string(8) "1,234.56"
float(1234.56)
de_DE.UTF-8
string(8) "1.234,56"
float(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-25 19:27 UTC] stas at zend dot com
It looks like it's ICU bug. It uses OS's decimal separator in its conversions (why???) and it remembers it only once, so if you change it with LC_ALL after you did some number conversion work, it's broken.
 [2009-01-30 15:59 UTC] stas at zend dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 27 23:03:35 2021 UTC