# Convert Numbers to Words in Indian System

#### by Sasikumar 2014-02-17 17:22:56

Function to convert numbers to words in Indian System:
This function converts numbers into words in indian system for values less than 100 Crores.
function numtowordsIndian(\$num)
{
\$ones = array( 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");
\$tens = array( 2 => "twenty",3 => "thirty",4 => "forty",5 => "fifty",6 => "sixty", 7 => "seventy",8 => "eighty",9 => "ninety");
\$hundreds = array("hundred","thousand","lakh","crore");
\$num = ereg_replace(",", "", \$num);
\$num = moneyFormatIn(\$num);
\$num_arr = explode(".",\$num);
\$wholenum = \$num_arr[0];
\$decnum = \$num_arr[1];
\$whole_arr = array_reverse(explode(",",\$wholenum));
krsort(\$whole_arr);
\$rettxt = "";
\$whole_arr_count = count(\$whole_arr);
\$loop = 1;
foreach(\$whole_arr as \$key => \$i)
{
if(\$loop<\$whole_arr_count)
{
if(\$whole_arr_count>4 && \$loop<(\$whole_arr_count-3))
{
\$rettxt = "Values less than 100 Crores can only be represent.";
return \$rettxt;
}
else
{
if(\$i < 20)
{
\$rettxt .= \$ones[\$i];
}
elseif(\$i < 100)
{
\$rettxt .= \$tens[substr(\$i,0,1)];
\$rettxt .= " ".\$ones[substr(\$i,1,1)];
}
else
{
\$rettxt .= \$ones[substr(\$i,0,1)]." ".\$hundreds[0];
\$rettxt .= " ".\$tens[substr(\$i,1,1)];
\$rettxt .= " ".\$ones[substr(\$i,2,1)];
}
if(\$key > 0){ \$rettxt .= " ".\$hundreds[\$key]." "; }
}

}
else
{
\$len = strlen(\$i);
if(\$len<=2)
\$rettxt .= \$ones[\$i];
else
{
\$hunderedplace = substr(\$i,0,1);
\$tensplace = (int)substr(\$i,1,2);
if(\$hunderedplace!="" && \$hunderedplace!="0")
\$rettxt .= \$ones[\$hunderedplace]." ".\$hundreds[0];
if(\$tensplace!="" && \$tensplace!=0)
{
\$rettxt .= " and ";
if(\$tensplace < 20)
\$rettxt .= \$ones[\$tensplace];
elseif(\$tensplace < 100)
{
\$rettxt .= \$tens[substr(\$tensplace,0,1)];
\$rettxt .= " ".\$ones[substr(\$tensplace,1,1)];
}
}
}
}
\$loop++;
}
if(\$decnum > 0)
{
\$rettxt .= " point ";
if(\$decnum < 20){
\$rettxt .= \$ones[\$decnum];
}elseif(\$decnum < 100){
\$rettxt .= \$tens[substr(\$decnum,0,1)];
\$rettxt .= " ".\$ones[substr(\$decnum,1,1)];
}
}
return \$rettxt;
}

For this function to work get the function "moneyFormatIn" from the below link,
moneyFormatIn

109
0
0