我对此非常头疼。为什么这段代码不起作用?
<?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,
],
]
答案 0 :(得分:2)
货币解析器非常奇怪,并且期望货币符号和数字之间存在非间隔空格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
是该突破空间的代码。