给个思路吧:
先将该数字3个一组分开,然后再判断
用一个函数
geten($num,$location)
其中$num是最大三位的数,$location是第几个三位数(从右向左)
比如geten(6,1)=>six thousand
geten(16,1)=>sixteen thousand
然后你再写个函数,将3位数字转换成为英文表示。
因为英文数字的单位是以3位数为基的,比如千、百万、十亿...
2位数的大至是这样的:20以内有单独的表示,大于20就有规律可循了。应该不会太难。
先将该数字3个一组分开,然后再判断
用一个函数
geten($num,$location)
其中$num是最大三位的数,$location是第几个三位数(从右向左)
比如geten(6,1)=>six thousand
geten(16,1)=>sixteen thousand
然后你再写个函数,将3位数字转换成为英文表示。
因为英文数字的单位是以3位数为基的,比如千、百万、十亿...
2位数的大至是这样的:20以内有单独的表示,大于20就有规律可循了。应该不会太难。
$数量级=array(1=>"Thousand",2=>"Million",3=>"Billion",4=>"Trillion",5=>"Quadrillion",6=>"Quintillion",7=>"Sextillion",8=>"Septillion",9=>"Octillion",10=>"Nonillion",11=>"Decillion",12=>"Undecillion",13=>"Duodecillion",14=>"Tredecillion",15=>"Septemdecillion",16=>"Octodecillion",17=>"Novemdecillion",18=>"Vigintillion");
function getnum($temp){
$个位级=array(1=>"One",2=>"Two",3=>"Three",4=>"Four",5=>"Five",6=>"Six",7=>"Seven",8=>"Eight",9=>"Nine",10=>"Ten"); $十位数=array(11=>"Eleven",12=>"Twelve",13=>"Thirteen",14=>"Fourteen",15=>"Fiftenn",16=>"Sixteen",17=>"Seventeen",18=>"Eighteen",19=>"Nineteen");
$十位级=array(2=>"Twenty",3=>"Thirty",4=>"Forty",5=>"Fifty",6=>"Sixty",7=>"Seventy",8=>"Eighty",9=>"Ninety");
if($temp<100){
$百=0;
$十=$temp;
}else{
$百=floor($temp/100);
$十=$temp%100;
}
if($百<>0){
$result=$个位级[$百]." Hundred";
}
if($十<11){
$result.=" ".$个位级[$十];
}elseif($十<20){
$result.=" ".$十位数[$十];
}else{
if($十%10==0) $result.=" ".$十位级[$十/10];
else $result.=" ".$十位级[floor($十/10)]."-".$个位级[$十%10];
}
return $result;
}
echo '<form method=post>';
echo '<input type=text name=num value='.$num.'>';
echo '<input type=submit name=submit value="确定">';
echo '</form>';if($submit){
$numtmp=$num;
for($i=0;$i<ceil(strlen($num)/3);$i++){
$arr[]=substr($numtmp,-3,3);
$numtmp=substr($numtmp,0,-3);
}
for($i=count($arr)-1;$i>=0;$i--){
$结果.=getnum($arr[$i])." <font color=blue>".$数量级[$i]."</font> ";
}
echo $结果;
}
?>