PHP 8.4.24 Released!

Voting

: max(four, seven)?
(Example: nine)

The Note You're Voting On

phpdeveloperbalaji at gmail dot com
14 years ago
Hi,

For South Asian Currencies, this function could be a handy one.

It will handle negative as well as float(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 = ".".substr($paise,0,2);
    }
    
    return $negative.$formatted_rupee.$formatted_paise;

}
?>

Thanks,

<< Back to user notes page

To Top