I'm configure my frontend/config/main.php:
'language' => 'ru-RU',
'components' => [
...
'formatter' => [
'dateFormat' => 'dd.MM.yyyy',
'decimalSeparator' => ',',
'thousandSeparator' => ' ',
'currencyCode' => 'RUB',
'numberFormatterOptions' => [
NumberFormatter::MIN_FRACTION_DIGITS => 0,
NumberFormatter::MAX_FRACTION_DIGITS => 2,
],
'numberFormatterSymbols' => [
NumberFormatter::CURRENCY_SYMBOL => 'โฝ',
]
],
],
When i writting
<?= Yii::$app->formatter->asCurrency(100000) ?>
i expect to see 100 000 โฝ (my symbol)
but i get 100 000,00 ััะฑ.
When i setting parameter numberFormatterSymbols, parameter numberFormatterOptions not working after (before result was 100 000 ััะฑ.)
| Q | A
| ---------------- | ---
| Yii version | 2.0.11.2?
| PHP version | 7.1.0
| Operating system | ubuntu/trusty64
| and i testing too on native vagrant settings of yii2 | same result
thats my first issue, sry if something wrong
@samdark is the issue verified?
No, not yet.
@Fisher-mast can you run the following in your environment?
$formatter = new NumberFormatter('ru_RU', NumberFormatter::CURRENCY);
$formatter->setSymbol(NumberFormatter::CURRENCY_SYMBOL, 'RUR1');
echo $formatter->formatCurrency(123, 'RUR');
@samdark sure,
result
123,00 ั.
Means your ICU version ignores setting currency symbol. I haven't found which versions are affected and if PHP version matters but I have the same issue reproduced at https://3v4l.org/7pPWr
@Fisher-mast one more thing to check. ICU version:
echo defined('INTL_ICU_VERSION') ? INTL_ICU_VERSION : 'no ICU';
Here's what I've found so far:
@samdark yep my version is 52.1
@samdark updated my icu to 58.2 version and CURRENCY SYMBOL working perfectly. But value NumberFormatter::MIN_FRACTION_DIGITS => 0 still igroring (somebody created new issue about this https://github.com/yiisoft/yii2/issues/13768).
If someone do not know how update ICU on php 7.0 - here tutor:
sudo su
Install ICU
wget http://download.icu-project.org/files/icu4c/58.2/icu4c-58_2-src.tgz
tar zxvf icu4c-58_2-src.tgz
cd icu/source
./configure --prefix=/opt/icu5c && make && make installInstall intl.so from php source
cd ../..
wget https://github.com/php/php-src/archive/php-7.0.15.tar.gz
tar -xvf php-7.0.15.tar.gz
cd php-src-php-7.0.15/ext/intlexport LD_LIBRARY_PATH=/opt/icu5c/lib
phpize
./configure --enable-intl --with-icu-dir=/opt/icu5c
make
make installActivate extension (cli and fpm)
echo "extension=intl.so" > /etc/php/7.0/mods-available/intl.ini
ln -s /etc/php/7.0/mods-available/intl.ini /etc/php/7.0/cli/conf.d/20-intl.ini
ln -s /etc/php/7.0/mods-available/intl.ini /etc/php/7.0/fpm/conf.d/20-intl.ini
You should not set 'currencyCode' => 'RUB', then it will be well done.
yep, setting currencyCode will override the symbol.
Sorry, a little out of topic, but, I want to set my thousand (.) and decimal (,) separator in my currency (example: Rp 12.500,50). My formatter code:
'formatter' => [
'defaultTimeZone' => 'UTC',
'timeZone' => 'Asia/Jakarta',
'dateFormat' => 'php:d-m-Y',
'datetimeFormat' => 'php:d-M-Y H:i:s',
'decimalSeparator' => ',',
'thousandSeparator' => '.',
'currencyCode' => 'Rp ',
'numberFormatterOptions' => [
NumberFormatter::MIN_FRACTION_DIGITS => 0,
NumberFormatter::MAX_FRACTION_DIGITS => 2,
],
],
The output is Rp 12.500.50 <- decimal is .
I'm expecting Rp 12.500,50 <- decimal is ,
What went wrong?
Thanks.
Sorry, a little out of topic, but, I want to set my thousand (.) and decimal (,) separator in my currency Have the same problem as metioned by tonny-sofijan.
thousandSeparator not working in asCurency
I am using Amazon Linux Image ( based on Centos 7) and can't find new version of ICU for my Linux version.The latest version available is ICU50.
Any workaround for this ?
Hi.
I am using yii en local machine.
I have an error:
Invalid Configuration โ yii\base\InvalidConfigException
The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.
cannot resolve. please helpme whit this error.
tk.
Well, install intl extension.
You can configure property currencyCode of Formatter component in app config:
https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter#$currencyCode-detail
..or just install php-intl extension package.
hanks. I'm launching yii from the command line:
_ php yii serve --port = 8083 --docroot = "frontend/web/"_
but not from xammp (in xaamp if that dll is there)
How do i launch yii from xammp?
Please, read XAMPP documentation.
https://www.yiiframework.com/wiki/100/yii-and-xampp-server-on-windows
Most helpful comment
Here's what I've found so far: