Localization

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!

You’ll have to do something like this:




<?php $formatter = new CNumberFormatter('en') ?>

	<?php echo $formatter->formatCurrency('10.11', 'USD'); ?>



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.

There’s already CApplication::numberFormatter. So your code is the same as:


echo Yii::app()->numberFormatter->formatCurrency(...);



Right you are, thanks for the tip!