Cooper
(Thmscpr)
1
I am trying to use CNumberFormatter::formatCurrency() however its giving me an error that _locale is not set in my controller.
I would imagine that locale would be set application wide with a suitable default, but it appears not.
How can I set the locale for my application?
Thanks!
Vince
(Vadimg88)
2
You’ll have to do something like this:
<?php $formatter = new CNumberFormatter('en') ?>
<?php echo $formatter->formatCurrency('10.11', 'USD'); ?>
Cooper
(Thmscpr)
3
Thanks. I ended up doing it like this:
$fm = new CNumberFormatter(Yii::app()->getLocale());
echo $fm->formatCurrency($val['display_price'], "USD");
I am curious with locale how Yii would return "USD" (or other currency) if multiple currencies/locales are available.
mikl
(Mike)
4
There’s already CApplication::numberFormatter. So your code is the same as:
echo Yii::app()->numberFormatter->formatCurrency(...);
Cooper
(Thmscpr)
5
Right you are, thanks for the tip!