Edit report at https://bugs.php.net/bug.php?id=53791&edit=1
ID: 53791
User updated by: jinmoku at hotmail dot com
Reported by: jinmoku at hotmail dot com
Summary: NumberFormat::parse fail with French thousands
separator
-Status: Feedback
+Status: Closed
Type: Bug
Package: I18N and L10N related
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
This is not a bug, the real test should be
-------------------------------
$nombre = 1234.56;
$fmt = new NumberFormatter('fr_FR', NumberFormatter::DECIMAL);
var_dump($fmt->format($nombre));
$nombre = "1\xc2\xa0234,56";
$fmt = new NumberFormatter('fr_FR', NumberFormatter::DECIMAL);
var_dump($fmt->parse($nombre));
$nombre = '1234,56';
$fmt = new NumberFormatter('fr_FR', NumberFormatter::DECIMAL);
var_dump($fmt->parse($nombre));
-------------------------------
-------------------------------
string(9) "1 234,56"
float(1234.56)
float(1234.56)
-------------------------------
Previous Comments:
------------------------------------------------------------------------
[2012-02-21 09:44:13] [email protected]
I spent a bit of time looking at this tonight. As far as I can tell there is
nothing wrong on the PHP side here. A quick ICU test program that reproduces
this bug is here:
== [unum.c] ========================
#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/unum.h"
#include "unicode/uloc.h"
#include "unicode/umisc.h"
#include "unicode/parseerr.h"
void main(int argc, char *argv[]) {
UChar tmp[64];
UNumberFormat *cur_def;
int32_t parsepos = 0;
UErrorCode status=U_ZERO_ERROR;
UNumberFormatStyle style= UNUM_DEFAULT;
double d;
cur_def = unum_open(style, NULL, 0, argv[1], NULL, &status);
if(U_FAILURE(status)) printf("Error1: %s\n", u_errorName(status));
u_uastrcpy(tmp, argv[2]);
d = unum_parseDouble(cur_def, tmp, u_strlen(tmp), &parsepos, &status);
if(U_FAILURE(status)) printf("Error2: %s\n", u_errorName(status));
printf("%f\n",d);
}
Compile with:
gcc -o unum unum.c -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm
or check what your flags should be on your platform with:
/usr/bin/icu-config --ldflags
then run it like this:
$ ./unum fr_FR "1234,56"
1234.560000
$ ./unum fr_FR "1 234,56"
1.000000
I get this with ICU 4.4.2 on Ubuntu.
Could someone please try this on ICU 4.6 or 4.8?
------------------------------------------------------------------------
[2011-12-10 04:57:26] playa71 at gmail dot com
Running PHP 5.3.8 on Win7 - this problem still happens.
Amazing in 2011 a programming language exists that doesn't support entire
countries! sigh.
------------------------------------------------------------------------
[2011-09-05 17:03:26] [email protected]
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
or 5.3.8
------------------------------------------------------------------------
[2011-09-05 16:56:50] jinmoku at hotmail dot com
in fact the french group sep is not a "space" but a "no-breaking space"
------------------------------------------------------------------------
[2011-07-13 08:38:46] jinmoku at hotmail dot com
Feedback sent
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53791
--
Edit this bug report at https://bugs.php.net/bug.php?id=53791&edit=1