Reputation: 1514
Is there any way to retrieve a notation of the currency like the following with the PHP NumberFormatter class:
100,00 EUR
Basically instead of the symbol € I want the ISO 3 code.
The alternative would be to omit the symbol completely, but I still want to keep the type as NumberFormatter:CURRENCY. Don't know how to do this either.
Is it about str_replace in the end?
Upvotes: 0
Views: 923
Reputation: 36214
You can set manually the currency symbol, with
$nf->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, '<my symbol>');
& then use the format()
method for formatting. But i think, that's not what you want. For example:
$nf_en = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
$nf_en->setTextAttribute(\NumberFormatter::CURRENCY_CODE, 'EUR');
$nf_en->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, 'EUR');
$nf_de = new \NumberFormatter('de', \NumberFormatter::CURRENCY);
$nf_de->setTextAttribute(\NumberFormatter::CURRENCY_CODE, 'EUR');
$nf_de->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, 'EUR');
echo $nf_en->format(1); // this will print 'EUR1.00'!
echo $nf_de->format(1); // this will print 'EUR 1,00'!
If you set the currency code to ''
, still there will be locales, where the formatted strings will start (or end) with white space(s). It would be easier to use the NumberFormatter
to format as a decimal number.
Upvotes: 1