note 105852 deleted from function.money-format by tularis
| From: | tularis@php.net | Date: | Tue, 20 Sep 2011 18:30:01 +0000 |
| Subject: | note 105852 deleted from function.money-format by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183310@lists.php.net to get a copy of this message | ||
Note Submitter: balaji dot sabal86 at gmail dot com
Reason: bad code
----
To get a Indian currency format, you can use this function..
It will handle negative numbers as well as paise.
<?php
function my_money_format($number)
{
if(strstr($number,"-"))
{
$number = str_replace("-","",$number);
$negative = "-";
}
$split_number = @explode(".",$number);
$rupee = $split_number[0];
$paise = $split_number[1];
if(@strlen($rupee)>3)
{
$hundreds = substr($rupee,strlen($rupee)-3);
$thousands_in_reverse = strrev(substr($rupee,0,strlen($rupee)-3));
for($i=0; $i<(strlen($thousands_in_reverse)); $i=$i+2)
{
$thousands .= $thousands_in_reverse[$i].$thousands_in_reverse[$i+1].",";
}
$thousands = strrev(trim($thousands,","));
$formatted_rupee = $thousands.",".$hundreds;
}
else
{
$formatted_rupee = $rupee;
}
if((int)$paise>0)
{
$formatted_paise = ".".$paise;
}
return $negative.$formatted_rupee.$formatted_paise;
}
echo my_money_format(-1123456789.24);
?>
Thanks