Home > Backend Development > PHP Tutorial > Convert numbers to English_PHP tutorial

Convert numbers to English_PHP tutorial

WBOY
Release: 2016-07-21 15:58:46
Original
797 people have browsed it

//*** Description: Convert numerical value to English representation
//=== Return:
//--- NN )Value FF) Decimal places
//========================================== =====================
function xf_num2en($NN, $FF=0) {
//===[prefix]== ======================================
if (!is_numeric($NN)) return '';
($FF>2) and $FF=2;
$xn=''; $enws= array( 
     0=>"zero",1=>"one",2=>"two",3=>"three",4=>"four", 
    5= >"five",6=>"six",7=>"seven",8=>"eight",9=>"nine",      " sixteen",17=>"seventeen",18=>"eighteen",19=>"nineteen",                                              "forty",50=>"fifty", 
     60=>"sixty",70=>"seventy",80=>"eighty",90=>"ninety");  
          //===[integer]==========================================  $ Nk = Floor ($ nn);
$ cNT = 0;
While ($ nk) {
$ n = $ nk%1000;
if ($ n) {                $x=xf_enNum4($n);                                     elseif ($cnt==2)                                                              . '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  
        //===[小數]========================================  
          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 ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317486.htmlTechArticle?php//___{xf_num2en}________________________________________ //***說明:數值轉英文表示法 //===回傳:string //---NN)數值FF)小數位 //===================================...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template