數(shù)字轉(zhuǎn)英文
更新時間:2006年12月06日 00:00:00 作者:
<?php //___{xf_num2en}________________________________________
//*** 說明: 數(shù)值轉(zhuǎn)英文表示法
//=== 回傳: <string>
//--- NN)數(shù)值 FF)小數(shù)位
//============================================================
function xf_num2en($NN, $FF=0) {
//===[前置]========================================
if (!is_numeric($NN)) return '';
($FF>2) and $FF=2;
$xn=''; $xf='';
global $enws;
$enws=array(
0=>"zero",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");
//===[整數(shù)]========================================
$nk=floor($NN);
$cnt=0;
while ($nk) {
$n=$nk % 1000;
if ($n) {
$x=xf_enNum4($n);
if ($cnt==1) $xn=$x. 'thousand '. $xn;
elseif ($cnt==2) $xn=$x. 'million '. $xn;
elseif ($cnt==3) $xn=$x. 'billion '. $xn;
elseif ($cnt==4) $xn=$x. 'trillion '. $xn;
else $xn=$x;
}
$cnt+=1;
$nk=floor($nk/1000);
} //--while
//===[小數(shù)]========================================
if ($FF>0) {
$n=floor($NN*100) % 100;
($n) and $xf=xf_enNum4($n). 'cent';
}
return $xn.$xf;
} //--xf_num2en
function xf_enNum4($NN) {
global $enws;
$ans='';
$n=floor($NN/100);
($n) and $ans=$enws[$n]. ' hundred ';
$n=$NN % 100;
if ($n) {
if ($n<20) $ans.=$enws[$n]. ' ';
else {
$m=floor($n/10) * 10;
$ans.=$enws[$m]. ' ';
$n=$n % 10;
($n) and $ans.=$enws[$n]. ' ';
}
}
return $ans;
} //--xf_enNum4 ?>
//*** 說明: 數(shù)值轉(zhuǎn)英文表示法
//=== 回傳: <string>
//--- NN)數(shù)值 FF)小數(shù)位
//============================================================
function xf_num2en($NN, $FF=0) {
//===[前置]========================================
if (!is_numeric($NN)) return '';
($FF>2) and $FF=2;
$xn=''; $xf='';
global $enws;
$enws=array(
0=>"zero",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");
//===[整數(shù)]========================================
$nk=floor($NN);
$cnt=0;
while ($nk) {
$n=$nk % 1000;
if ($n) {
$x=xf_enNum4($n);
if ($cnt==1) $xn=$x. 'thousand '. $xn;
elseif ($cnt==2) $xn=$x. 'million '. $xn;
elseif ($cnt==3) $xn=$x. 'billion '. $xn;
elseif ($cnt==4) $xn=$x. 'trillion '. $xn;
else $xn=$x;
}
$cnt+=1;
$nk=floor($nk/1000);
} //--while
//===[小數(shù)]========================================
if ($FF>0) {
$n=floor($NN*100) % 100;
($n) and $xf=xf_enNum4($n). 'cent';
}
return $xn.$xf;
} //--xf_num2en
function xf_enNum4($NN) {
global $enws;
$ans='';
$n=floor($NN/100);
($n) and $ans=$enws[$n]. ' hundred ';
$n=$NN % 100;
if ($n) {
if ($n<20) $ans.=$enws[$n]. ' ';
else {
$m=floor($n/10) * 10;
$ans.=$enws[$m]. ' ';
$n=$n % 10;
($n) and $ans.=$enws[$n]. ' ';
}
}
return $ans;
} //--xf_enNum4 ?>
相關(guān)文章
php 替換文章中的圖片路徑,下載圖片到本地服務(wù)器的方法
下面小編就為大家分享一篇php 替換文章中的圖片路徑,下載圖片到本地服務(wù)器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
ThinkPHP5 框架引入 Go AOP,PHP AOP編程項目詳解
這篇文章主要介紹了ThinkPHP5 框架引入 Go AOP,PHP AOP編程,結(jié)合具體項目項目分析了ThinkPHP5 引入 Go AOP,PHP AOP編程相關(guān)概念、原理、操作技巧與注意事項,需要的朋友可以參考下2020-05-05
php強(qiáng)制文件下載而非在瀏覽器打開的自定義函數(shù)分享
這篇文章主要介紹了php強(qiáng)制文件下載而非在瀏覽器打開的自定義函數(shù)分享,需要的朋友可以參考下
2014-05-05
phpstudy2020搭建站點(diǎn)的實現(xiàn)示例
這篇文章主要介紹了phpstudy2020搭建站點(diǎn)的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
2020-10-10 
