'', 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 : '') . $paise . ""; } /** * Function to dislay tens and ones */ function commonloop($val, $str1 = '', $str2 = '') { global $ones, $tens; $string = ''; if ($val == 0) $string .= $ones[$val]; else if ($val < 20) $string .= $str1.$ones[$val] . $str2; else $string .= $str1 . $tens[(int) ($val / 10)] . $ones[$val % 10] . $str2; return $string; } /** * returns the number as an anglicized string */ function convertNum($num) { $num = (int) $num; // make sure it's an integer if ($num < 0) return 'negative' . convertTri(-$num, 0); if ($num == 0) return 'Zero'; return convertTri($num, 0); } /** * recursive fn, converts numbers to words */ function convertTri($num, $tri) { global $ones, $tens, $triplets, $count; $test = $num; $count++; // chunk the number, ...rxyy // init the output string $str = ''; // to display hundred & digits if ($count == 1) { $r = (int) ($num / 1000); $x = ($num / 100) % 10; $y = $num % 100; // do hundreds if ($x > 0) { $str = $ones[$x] . ' Hundred'; // do ones and tens $str .= commonloop($y, ' and ', ''); } else if ($r > 0) { // do ones and tens $str .= commonloop($y, ' and ', ''); } else { // do ones and tens $str .= commonloop($y); } } // To display lakh and thousands else if($count == 2) { $r = (int) ($num / 10000); $x = ($num / 100) % 100; $y = $num % 100; $str .= commonloop($x, '', ' Lakh '); $str .= commonloop($y); if ($str != '') $str .= $triplets[$tri]; } // to display till hundred crore else if($count == 3) { $r = (int) ($num / 1000); $x = ($num / 100) % 10; $y = $num % 100; // do hundreds if ($x > 0) { $str = $ones[$x] . ' Hundred'; // do ones and tens $str .= commonloop($y,' and ',' Crore '); } else if ($r > 0) { // do ones and tens $str .= commonloop($y,' and ',' Crore '); } else { // do ones and tens $str .= commonloop($y); } } else { $r = (int) ($num / 1000); } // add triplet modifier only if there // is some output to be modified... // continue recursing? if ($r > 0) return convertTri($r, $tri+1) . $str; else return $str; } ?>