Ad Code

Convert number to words in indian rupees in php

function number_to_words ($x){

$nwords = array("", "one", "two", "three", "four", "five", "six","seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen", "twenty", 30 => "thirty", 40 => "fourty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eigthy", 90 => "ninety" );


$x = str_replace(',','',$x);

if(!is_numeric($x)){ $w = '#'; }elseif(fmod($x, 1) != 0){ $w = '#'; }else{

if($x < 0){ $w = 'minus '; $x = -$x; }else{ $w = ''; }

if($x < 21){

$w .= $nwords[$x];

}elseif($x < 100){

$w .= $nwords[10 * floor($x/10)];

$r = fmod($x, 10);

if($r > 0){ $w .= ' '. $nwords[$r]; }

}else if($x < 1000){

$w .= $nwords[floor($x/100)] .' hundred';

$r = fmod($x, 100);

if($r > 0){ $w .= ' '. number_to_words($r); }

}elseif($x < 1000000){

$w .= number_to_words(floor($x/1000)) .' thousand';

$r = fmod($x, 1000);

if($r > 0){

$w .= ' ';

if($r < 100){ $w .= ' '; }

$w .= number_to_words($r);

}

}else{

$w .= number_to_words(floor($x/100000)) .' lacs';

$r = fmod($x, 1000000);

if($r > 0){

$w .= ' ';

if($r < 100){ $word .= ' '; }

$w .= number_to_words($r);

}

}

}

return $w;
}

Post a Comment

0 Comments