I'm using this code to display an amount in the current locale.
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%i', $number);
My question is, how can I see the current value for LC_MONETARY ? If I do a simple echo the value seems the same and I can't find any getlocale function.
echo LC_MONETARY;
setlocale(LC_MONETARY, 'it_IT');
echo LC_MONETARY;
Update : LC_MONETARY is the category of function affected so it makes sense the value is the same. But how can I see the current locale info then ?
$oldLocale = setlocale(LC_MONETARY, 'it_IT');
// setlocale() will return the old value if the locale could
// be set (return value greatly depends on the system's underlying
// setlocale() implementation)
$oldLocale = setlocale(LC_MONETARY, '0');
// using '0' as the locale-argument will result in the current setting
//being returned without affecting the locale setting itself
See the note for the $locale parameter in the setlocale() documentation.
The value of the constant LC_MONETARY will never change. When setting a locale with setlocale(LC_MONETARY, ...), you're not changing the LC_MONETARY constant, you're setting the locale for the "monetary" category. This locale setting happens in the background and is not visible outwardly. The LC_MONETARY constant is just an identifier for the category.
Usually you don't need to know what's currently set. You should simply set your desired locale when needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With