简体   繁体   中英

LC_MONETARY it_IT@utf8 shows euro symbol before amount with PHP

Setting the locale information as:

$locale = 'it_IT';
$moneyFormat = '%n';

setlocale(LC_MONETARY, $locale.'.utf8');
$optionPrice = money_format($moneyFormat, floatval($option->optionPrice));

The price is shown as:

€ 23

instead

23 €

I've found the locale identifier p_sign_posn to set the position of the currency symbol but I don't know how to modify it and apparently it's set by default to 1 for the IT locale.

Anybody could enlightenment me to find a clever solution?

Thanks in advance.

EDIT: The locale for Italy is apparently installed on the system

vmamp@AMP30:~> locale -a | grep it
it_CH
it_CH.utf8
it_IT
it_IT.utf8
it_IT@euro

To use locale-aware function you have to have the requested locale installed on your computer. If the requested locale is not presented, the call to setlocale fails and nothing is changed.

For instance, I have es_ES locale installed, but no it_IT :

setlocale(LC_MONETARY, 'es_ES.utf8');
echo money_format($moneyFormat, floatval(12))
// ⇒ 12,00 €
setlocale(LC_MONETARY, 'en_US.utf8');
echo money_format($moneyFormat, floatval(12))
// ⇒ $12.00
setlocale(LC_MONETARY, 'it_IT.utf8');
echo money_format($moneyFormat, floatval(12))
//   FAIL!!!
// ⇒ $12.00

As you can see, the latter call was ignored ( setlocale returned 0 .) So the problem you encountered is not with a position of eurosign; it's likely a lack of it_IT l10n installed.

For italian currency mode you can do:

$money = substr(money_format('%.2n',$number), 4).' €';

given $number = 77500

you get

77.500,00 €

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM