|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
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?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) -------------------------------