formatter asDecimal set max fraction digits

I encounter error when trying to set NumberFormatter::MAX_FRACTION_DIGITS in formatter




<?php 

echo \Yii::$app->formatter->asCurrency($number, NULL, [\NumberFormatter::MAX_FRACTION_DIGITS => 8]);

?>



Got Class ‘NumberFormatter’ not found exception. I’ve enabled php_intl extension but dont see it under phpinfo() ?

How to fix the issue ?

do you have PHP intl extension installed? This is required to use NumberFormatter as well as all of the other classes in the link. Also, you can set all of your formatting in your config file so you don’t have to do it everywhere.




'components' => [

 'formatter' => [

   'dateFormat' => 'yyyy-MM-dd',

   'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',

   'decimalSeparator' => '.',

   'thousandSeparator' => ',',

   'currencyCode' => 'USD',

   'numberFormatterOptions'=>[

	\NumberFormatter::MIN_FRACTION_DIGITS => 0,

	\NumberFormatter::MAX_FRACTION_DIGITS => 8

   ]

 ]

]



@nguyendh are you using Wamp?

@bizley I am using AMPPS (http://www.ampps.com/)

@skworden I enabled php_intl extension, and restarted the Apache server several time.

It says there is wamp inside as well, so it might have the same problem as with wamp - check this answer http://stackoverflow.com/a/16372984/3364821

Have you tried restarting your machine? I use ampps as well and sometimes have to restart because it will not restart properly. I installed the intl ext. in the control panel as normal and it worked for me.

I’m using

v 2.5 (& 2.8 on differnt machine)

php 5.5

I had some issues with mongo and php so i can’t use the latest versions with ampps

Did it actually install the extension? You can quickly check all of your extensions by using the following:


<?= "<pre>", print_r(get_loaded_extensions())?>