Its a small utility to convert Indian currency to words format
CONFIGURATION: ¶
Config - main.php
'components' => array(
'currency_formator' => array(
'class' => 'ext.yii-extension-INRCurrencyFormator.INRCurrencyFormator',
'params' => array(
'postfix' => 'only',
'currency' => '₹'
)
),
);
Usage ¶
$converter = Yii::app()->currency_formator;
echo $converter->toWords('12');
// Twelve Rs. only
echo $converter->toWords('123');
// One Hundred and Twenty-Three Rs. only
echo $converter->toWords('1234');
// One Thousand Two Hundred and Thirty-Four Rs. only
echo $converter->toWords('12345');
// Twelve Thousand Three Hundred and Fourty-Five Rs. only
echo $converter->toWords('123456');
// One Lakh Twenty-Three Thousand Four Hundred and Fifty-Six Rs. only
echo $converter->toWords('12345600');
// One Crore Twenty-Three Lakh Fourty-Five Thousand Six Hundred Rs. only
Currency symbol can be changed like this ¶
You can set in config for global configuration
$converter = Yii::app()->currency_formator;
$converter->currency = '₹';
echo $converter->toWords('12');
// Twelve ₹ only
Postfix text can be changed like this
You can set in config for global configuration
$converter = Yii::app()->currency_formator;
$converter->postfix = 'payable';
echo $converter->toWords('12');
// Twelve ₹ payable
Postfix text and currency can be disabled like this ¶
$converter = Yii::app()->currency_formator;
echo $converter->toWords('12','no_postfixtext');
// Twelve
intl
You know you can also use the intl extension provided by PHP?
~~~
$f = new NumberFormatter('pl_PL', NumberFormatter::SPELLOUT);
$f->setTextAttribute(NumberFormatter::DEFAULT_RULESET, '%spellout-ordinal');
echo $f->format(1234567898);
~~~
Yes we can use intl, but intl doesn't handle some case
This is mainly for Indian Currency Format, In India for Rs. 100,000 We call it one lakh not one hundred thousandth. Which is not possible with NumberFormatter :)
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.