Convert Number to Indian Currency in PHP Php by Rajesh Kumar Sahanee - October 8, 2017April 14, 20200 Post Views: 18,537 Hello Friends, Today I am going to share how to convert number to Indian currency in PHP. Actually recently I was developing a billing software in which I was required to convert billing amount to words, so I thought to share this code to everyone so that anyone else developing any software which required currency conversion can use it. So, Here is the code ConvertToIndianCurrency.php PHP <?php function convertToIndianCurrency($number) { $no = round($number); $decimal = round($number - ($no = floor($number)), 2) * 100; $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; $str [] = ($number < 21) ? $words[$number] . ' ' . $digits[$counter] . $plural : $words[floor($number / 10) * 10] . ' ' . $words[$number % 10] . ' ' . $digits[$counter] . $plural; } else { $str [] = null; } } $Rupees = implode(' ', array_reverse($str)); $paise = ($decimal) ? "And Paise " . ($words[$decimal - $decimal%10]) ." " .($words[$decimal%10]) : ''; return ($Rupees ? 'Rupees ' . $Rupees : '') . $paise . " Only"; } echo "56721351.61 = " . convertToIndianCurrency(56721351.61); 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 <?php function convertToIndianCurrency($number) { $no = round($number); $decimal = round($number - ($no = floor($number)), 2) * 100; $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; $str [] = ($number < 21) ? $words[$number] . ' ' . $digits[$counter] . $plural : $words[floor($number / 10) * 10] . ' ' . $words[$number % 10] . ' ' . $digits[$counter] . $plural; } else { $str [] = null; } } $Rupees = implode(' ', array_reverse($str)); $paise = ($decimal) ? "And Paise " . ($words[$decimal - $decimal%10]) ." " .($words[$decimal%10]) : ''; return ($Rupees ? 'Rupees ' . $Rupees : '') . $paise . " Only";} echo "56721351.61 = " . convertToIndianCurrency(56721351.61); Output 56721351.61 = Rupees Five Crore Sixty Seven Lakhs Twenty One Thousands Three Hundred Fifty One And Paise Sixty One Only Thanks Please share if you like it