![](/img/trans.png)
[英]NumberFormatter::parseCurrency gives different results on machines with same PHP version
[英]PHP NumberFormatter parseCurrency returning false
我正在尝试这个:
public static function money($str)
{
$currency = 'BRL';
$formatter = new \NumberFormatter('pt_BR', \NumberFormatter::CURRENCY);
return $formatter->parseCurrency($str, $currency);
}
我试图将像“R$ 123,45”这样的字符串解析为“123.45”,但每次都返回false
。
根据 ISO 4217 BRL
是巴西货币的代码: https : //en.wikipedia.org/wiki/ISO_4217
我究竟做错了什么?
这应该工作
public function currency($str, $currency = 'BRL')
{
// use of NumberFormatter from extension //
$formatter = new \NumberFormatter('pt_BR', \NumberFormatter::CURRENCY);
return $formatter->formatCurrency($str, $currency);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.