NumberFormatter 用逗号解析欧元作为十进制分隔符

NumberFormatter parse Euro's with comma as decimal splitter

为此我很头疼。为什么此代码不起作用?

<?php
setlocale(LC_MONETARY, 'nl');
$fmt = new NumberFormatter( 'nl', NumberFormatter::CURRENCY );
$num = "€2,50";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

我已经在 Windows 机器和 http://phpfiddle.org/ 上试过了。预期结果是 We have 2.50 in EUR

荷兰语语言环境如下:

>>> localeconv()
=> [
     "decimal_point" => ",",
     "thousands_sep" => ".",
     "int_curr_symbol" => "EUR",
     "currency_symbol" => b"€",
     "mon_decimal_point" => ",",
     "mon_thousands_sep" => ".",
     "positive_sign" => "",
     "negative_sign" => "-",
     "int_frac_digits" => 2,
     "frac_digits" => 2,
     "p_cs_precedes" => 1,
     "p_sep_by_space" => 1,
     "n_cs_precedes" => 1,
     "n_sep_by_space" => 1,
     "p_sign_posn" => 4,
     "n_sign_posn" => 4,
     "grouping" => [
       3,
     ],
     "mon_grouping" => [
       3,
     ],
   ]

货币解析器非常奇怪,需要在货币符号和数字之间使用非破坏性 space UTF-8 符号。 这个例子对我来说很好用:

<?php
setlocale(LC_MONETARY, 'nl');
$fmt = new NumberFormatter( 'nl', NumberFormatter::CURRENCY );
$num = "€\xc2\xa02,50";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

\xc2\xa0 是打破 space.

的代码