Returning amount of money in Indian ruppes to Crores / Lakhs / Thousands

<?php
define('INR_THOUSAND', 1000);
define('INR_LAKH', 100 * INR_THOUSAND);
define('INR_CRORE', 100 * INR_LAKH);

echo amountInINR(15000)."\n";
echo amountInINR(1500000)."\n";
echo amountInINR(150000000)."\n";
echo amountInINR(9876543210)."\n";

function amountInINR($amount)
{
    $INR = $amount;
    $ext = "";

    if ($amount > INR_CRORE)
    {
        $INR = $amount / INR_CRORE;
        $ext = $INR == 1 ? "crore" : "crores";
        $INR = number_format($amount / INR_CRORE, 2).' '.$ext;
    }
    elseif ($amount > INR_LAKH)
    {
        $INR = $amount / INR_LAKH;
        $ext = $INR == 1 ? "lakh" : "lakhs";
        $INR = number_format($amount / INR_LAKH, 2).' '.$ext;
    }
    elseif ($amount > INR_THOUSAND)
    {
        $INR = $amount / INR_THOUSAND;
        $ext = $INR == 1 ? "lakh" : "K";
        $INR = number_format($amount / INR_THOUSAND, 2).' '.$ext;
    }    
    else
    {
        $INR = number_format($amount, 2);
    }

    return str_replace(".00", "", $INR);
}
?>

No Comments Yet