Skip to main content

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

Published 0 min readMarkdown
<?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);
}
?>

67 views

About the author

  • I am a web consultant from Navi Mumbai. Mainly dealt with LAMP stack, now into Django and getting into Laravel and Cloud. Founder of nerul.in and gaali.in

No comments yet. Be the first to comment.