Created
July 24, 2019 10:22
-
-
Save anehkumar/052af54fbeeae2b9cd5133975f5a1d39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getIndianCurrency(float $number) | |
{ | |
$decimal = round($number - ($no = floor($number)), 2) * 100; | |
$hundred = null; | |
$digits_length = strlen($no); | |
$i = 0; | |
$str = array(); | |
$words = array(0 => '', 1 => 'one', 2 => 'two', | |
3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', | |
7 => 'seven', 8 => 'eight', 9 => 'nine', | |
10 => 'ten', 11 => 'eleven', 12 => 'twelve', | |
13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', | |
16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', | |
19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', | |
40 => 'forty', 50 => 'fifty', 60 => 'sixty', | |
70 => 'seventy', 80 => 'eighty', 90 => 'ninety'); | |
$digits = array('', 'hundred','thousand','lakh', 'crore'); | |
while( $i < $digits_length ) { | |
$divider = ($i == 2) ? 10 : 100; | |
$number = floor($no % $divider); | |
$no = floor($no / $divider); | |
$i += $divider == 10 ? 1 : 2; | |
if ($number) { | |
$plural = (($counter = count($str)) && $number > 9) ? 's' : null; | |
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null; | |
$str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred; | |
} else $str[] = null; | |
} | |
$Rupees = implode('', array_reverse($str)); | |
$paise = ($decimal) ? " and " . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : ''; | |
$word = ($Rupees ? $Rupees . '' : '') . $paise." Only"; | |
return ucwords(strtolower($word)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment