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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bjoernhaeuser at gmail dot com
New email:
PHP Version: OS:

 

 [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: Thu Oct 28 00:03:33 2021 UTC