Yii Framework, currency format using the number formatter

May 22, 2016 17 Alex

A simple example of formatting the currency in Yii

<?php
//American dollar
echo Yii::app()->numberFormatter->formatCurrency(1234.5678, 'USD'); // 1 234,57 $

//Euro
echo Yii::app()->numberFormatter->formatCurrency(1234.5678, 'EUR'); // 1 234,57 €

//Ukrainian hryvnia
echo Yii::app()->numberFormatter->formatCurrency(1234.5678, 'UAH'); // 1 234,57 ₴

//Russian ruble
echo Yii::app()->numberFormatter->formatCurrency(1234.5678, 'RUB'); // 1 234,57 руб.