note 97020 added to function.number-format
| From: | dipu dot ashok dot 17 at gmail dot com | Date: | Sun, 28 Mar 2010 21:18:07 +0000 |
| Subject: | note 97020 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167469@lists.php.net to get a copy of this message | ||
function to convert numbers to words
indian: thousand,lakh,crore
Note: function can only convert nos upto 99 crores
<?php
$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' =>
'fouteen','15' => 'fifteen','16' =>
'sixteen','17' => 'seventeen','18' =>
'eighteen','19' => 'nineteen','20' =>
'twenty','30' => 'thirty','40' =>
'fourty','50' => 'fifty','60' =>
'sixty','70' => 'seventy','80' =>
'eighty','90' => 'ninty','100' => 'hundred
&','1000' => 'thousand','100000' =>
'lakh','10000000' => 'crore');
function no_to_words($no)
{ global $words;
if($no == 0)
return ' ';
else { $novalue='';$highno=$no;$remainno=0;$value=100;$value1=1000;
while($no>=100) {
if(($value <= $no) &&($no < $value1)) {
$novalue=$words["$value"];
$highno = (int)($no/$value);
$remainno = $no % $value;
break;
}
$value= $value1;
$value1 = $value * 100;
}
if(array_key_exists("$highno",$words))
return $words["$highno"]." ".$novalue." ".no_to_words($remainno);
else {
$unit=$highno%10;
$ten =(int)($highno/10)*10;
return $words["$ten"]." ".$words["$unit"]."
".$novalue." ".no_to_words($remainno);
}
}
}
echo no_to_words(999978987);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 114.79.146.111
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/97020
Del: integrated -- https://master.php.net/note/delete/97020/integrated
Del: useless -- https://master.php.net/note/delete/97020/useless
Del: bad code -- https://master.php.net/note/delete/97020/bad+code
Del: spam -- https://master.php.net/note/delete/97020/spam
Del: non-english -- https://master.php.net/note/delete/97020/non-english
Del: in docs -- https://master.php.net/note/delete/97020/in+docs
Del: other reasons-- https://master.php.net/note/delete/97020
Reject -- https://master.php.net/note/reject/97020
Search -- https://master.php.net/manage/user-notes.php