Skip to content

Instantly share code, notes, and snippets.

@vandro
Forked from umidjons/number-format.md
Created August 5, 2017 20:50
Show Gist options
  • Save vandro/07dac8b82f43664e73a834a8da744662 to your computer and use it in GitHub Desktop.
Save vandro/07dac8b82f43664e73a834a8da744662 to your computer and use it in GitHub Desktop.
Yii: Using Number formatter in Yii

Using Number formatter in Yii

<?php
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'USD'); // 1 234,57 $
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'EUR'); // 1 234,57 €
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'RUB'); // 1 234,57 руб.

It is easy do this with wrapper function:

<?php
function formatCurrency($value, $currency = "USD")
{
	return Yii::app()->numberFormatter->formatCurrency($value, $currency);
}

formatCurrency(1234.5678, 'USD'); // 1 234,57 $
formatCurrency(1234.5678, 'EUR'); // 1 234,57 €
formatCurrency(1234.5678, 'RUB'); // 1 234,57 руб.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment