[英]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.