I'm trying this:
public static function money($str)
{
$currency = 'BRL';
$formatter = new \NumberFormatter('pt_BR', \NumberFormatter::CURRENCY);
return $formatter->parseCurrency($str, $currency);
}
I'm trying to parse a string like "R$ 123,45" to "123.45", but it returns false
everytime.
According to ISO 4217 BRL
is the CODE for Brazil currency: https://en.wikipedia.org/wiki/ISO_4217
What am i doing wrong?
This should work
public function currency($str, $currency = 'BRL')
{
// use of NumberFormatter from extension //
$formatter = new \NumberFormatter('pt_BR', \NumberFormatter::CURRENCY);
return $formatter->formatCurrency($str, $currency);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.