php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53791 NumberFormat::parse fail with French thousands separator
Submitted: 2011-01-19 16:52 UTC Modified: 2012-02-21 10:03 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: jinmoku at hotmail dot com Assigned: derick (profile)
Status: Closed Package: I18N and L10N related
PHP Version: 5.3.5 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jinmoku at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-01-19 16:52 UTC] jinmoku at hotmail dot com
Description:
------------
NumberFormat::parse fail with French thousands separator (space)

Test script:
---------------
$nombre = '1234,56';
$fmt = new NumberFormatter('fr_FR', NumberFormatter::DECIMAL);
var_dump($fmt->format($nombre));

$nombre = '1 234,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));

Expected result:
----------------
string(9) "1 234,56"
float(1234.56)
float(1234.56)


Actual result:
--------------
string(9) "1 234,56"
float(1)
float(1234.56)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-19 16:55 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-01-19 16:55 UTC] pajoye@php.net
Which ICU version do you use?
 [2011-01-19 18:05 UTC] jinmoku at hotmail dot com
-Status: Feedback +Status: Open
 [2011-01-19 18:05 UTC] jinmoku at hotmail dot com
intl 1.1.0 icu 3.6 and win 7

On debian dotdeb php 5.2.14 with icu 3.8.1 (intl 1.0.3), I have :

string(9) "1Â 234,56"
float(1)
float(1234.56)
 [2011-01-19 18:23 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-01-19 18:23 UTC] pajoye@php.net
Looks to me like an ICU problem then.

Please try VC9 builds on Windows instead of VC6, as we use 3.8.x instead of 3.6.
 [2011-01-19 19:50 UTC] jinmoku at hotmail dot com
I can't try now, but I tested on my OSX with php 5.3.5 and ICU 4.6, and I have :

string(6) "1 234"
float(1)
float(1234.56)
 [2011-01-21 17:08 UTC] jinmoku at hotmail dot com
On VC9 :

string(6) "1 234"
float(1)
float(1234.56)
 [2011-07-13 08:38 UTC] jinmoku at hotmail dot com
-Status: Feedback +Status: Open
 [2011-07-13 08:38 UTC] jinmoku at hotmail dot com
Feedback sent
 [2011-09-05 16:56 UTC] jinmoku at hotmail dot com
in fact the french group sep is not a "space" but a "no-breaking space"
 [2011-09-05 17:03 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-09-05 17:03 UTC] pajoye@php.net
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-12-10 04:57 UTC] 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.
 [2012-02-21 09:44 UTC] rasmus@php.net
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?
 [2012-02-21 10:00 UTC] jinmoku at hotmail dot com
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)
-------------------------------
 [2012-02-21 10:00 UTC] jinmoku at hotmail dot com
-Status: Feedback +Status: Closed
 [2012-02-21 10:00 UTC] derick@php.net
-Status: Closed +Status: Feedback
 [2012-02-21 10:00 UTC] derick@php.net
4.8.1 gives:

derick@whisky:/tmp$ ./unum fr_FR "1 234.56"
1234.000000

derick@whisky:/tmp$ ./unum fr_FR "1 234,56"
1234.560000

derick@whisky:/tmp$ ./unum fr_FR "1234,56"
1234.560000
 [2012-02-21 10:01 UTC] derick@php.net
Ok, in any case, in 4.8.1 a normal space seems to work as well.
 [2012-02-21 10:01 UTC] derick@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: derick
 [2012-02-21 10:03 UTC] rasmus@php.net
Jinmoku, well, they fixed this non-bug in ICU 4.8 it seems. It really should work 
with spaces.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC