-
-
- /*
- Only supports converting integer lowercase amounts to Chinese uppercase
- */
- class ChineseNumber
- {
- //var $basical=array(0=>"zero" ,"one","two","three","four","five","six","seven","eight","nine");
- var $basical=array(0=>" Zero", "one", "two", "three", "four", "five", "Lu", "旒", "eight", "玖");
- //var $advanced=array(1 =>"十","百","千");
- var $advanced=array(1=>"十","百","千");
- var $top=array(1=> ;"10,000","100 million");
var $level; // Use 4 digits as one level
// First implement the 10,000 level Number conversion
- function small2big($number)
- {
- if ($number>999999999999) // Can only handle hundreds of billions.
- return "The number is too large to handle. Sorry!";
- if ($number==0)
- return "zero";
for($this->level=0; $number>0.0001;$this->level++,$number=floor($number / 10000))
- {
- // For Chinese, it should be a group of 4 digits.
- // The four variables correspond to units, tens, hundreds, and thousands respectively.
- $n1=substr($number,-1,1);
- if($number>9)
- $n2=substr($number,-2,1);
- else
- $n2=0;
- if($ number>99)
- $n3=substr($number,-3,1);
- else
- $n3=0;
- if($number>999)
- $n4=substr($number,-4,1);
- else
- $n4=0;
if($n4)
- $parsed[$this->level].=$this->basical[$n4].$this- >advanced[3];
- else
- if(($number/10000)>=1) // The thousands digit is 0 and the value is greater than 9999
- $parsed[$this->level].="zero ";
- if($n3)
- $parsed[$this->level].=$this->basical[$n3].$this->advanced[2];
- else
- if(!ereg( "Zero$",$parsed[$this->level]) && ($number / 1000)>=1) //There will be no two consecutive "zeros"
- $parsed[$this->level ].="zero";
- if($n2)
- $parsed[$this->level].=$this->basical[$n2].$this->advanced[1];
- else
- if(!ereg("zero$",$parsed[$this->level]) && ($number / 100)>=1) //There will be no two consecutive "zeros"
- $parsed[$ this->level].="zero";
- if($n1)
- $parsed[$this->level].=$this->basical[$n1];
- }
- for($this- >level-=1;$this->level>=0;$this->level--)
- {
- $result.=$parsed[$this->level].$this->top [$this->level];
- }
if(ereg("zero$",$result))
- $result=substr($result,0,strlen($result) -2);
return $result;
- }
- };
$big=new ChineseNumber();
- echo $big->small2big( 1311);
- ?>
-
Copy code
|