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!
Page 1 of 1
Localization how is it set
#2
Posted 16 April 2010 - 01:30 AM
You'll have to do something like this:
<?php $formatter = new CNumberFormatter('en') ?>
<?php echo $formatter->formatCurrency('10.11', 'USD'); ?>
#3
Posted 16 April 2010 - 02:18 AM
Thanks. I ended up doing it like this:
I am curious with locale how Yii would return "USD" (or other currency) if multiple currencies/locales are available.
$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.
#4
Posted 16 April 2010 - 02:53 AM
Cooper, on 16 April 2010 - 02:18 AM, said:
Thanks. I ended up doing it like this:
$fm = new CNumberFormatter(Yii::app()->getLocale()); echo $fm->formatCurrency($val['display_price'], "USD");
There's already CApplication::numberFormatter. So your code is the same as:
echo Yii::app()->numberFormatter->formatCurrency(...);
#5
Posted 16 April 2010 - 11:52 AM
Mike, on 16 April 2010 - 02:53 AM, said:
There's already CApplication::numberFormatter. So your code is the same as:
echo Yii::app()->numberFormatter->formatCurrency(...);
Right you are, thanks for the tip!
Share this topic:
Page 1 of 1

Help
















