The system is involved in the financial, contract and other aspects of the processing, often need to convert the amount of digital money into the capital amount of Chinese characters (seemingly so formal), turn a converted PHP class bar!
<?php
Sea Plus (ALPHA z)
2000-7-19
Class Chinesenumber
{
var $basical =array (0=> "0", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");
var $basical =array (0=> "0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU");
var $advanced =array (1=> "Ten", "Hundred", "thousand");
var $advanced =array (1=> "Pick", "Bai", "Qian");
var $top =array (1=> "million", "million");
var $level; 4-bit as a level
First realize the conversion of the number in case
function Parsenumber ($number)
{
if ($number >999999999999)//can only be processed to hundreds of billions.
Return "The number is too large to handle. I'm sorry! ";
if ($number ==0)
return "0";
For ($this->level=0; $number >0.0001; $this->level++, $number =floor ($number/10000))
{
For Chinese, it should be a group of 4 bits.
The four variables correspond to one, ten, hundred, and thousands respectively.
$n 1=substr ($number, -1,1);
if ($number >9)
$n 2=substr ($number, -2,1);
Else
$n 2=0;
if ($number >99)
$n 3=substr ($number, -3,1);
Else
$n 3=0;
if ($number >999)
$n 4=substr ($number, -4,1);
Else
$n 4=0;
if ($n 4)
$parsed [$this->level].= $this->basical[$n 4]. $this->advanced[3];
Else
if (($number/10000) >=1)//thousand is 0 and the value is greater than 9999
$parsed [$this->level].= "0";
if ($n 3)
$parsed [$this->level].= $this->basical[$n 3]. $this->advanced[2];
Else
if (!ereg ("0 $", $parsed [$this->level]) && ($number/1000) >=1)//Do not appear two consecutive "0" cases
$parsed [$this->level].= "0";
if ($n 2)
$parsed [$this->level].= $this->basical[$n 2]. $this->advanced[1];
Else
if (!ereg ("0 $", $parsed [$this->level]) && ($number/100) >=1)//Do not appear two consecutive "0" cases
$parsed [$this->level].= "0";
if ($n 1)
$parsed [$this->level].= $this->basical[$n 1];
}
For ($this->level-=1; $this->level>=0; $this->level--)
{
$result. = $parsed [$this->level]. $this->top[$this->level];
}
if (Ereg ("0 $", $result))
$result =substr ($result, 0,strlen ($result)-2);
return $result;
}
};
$c =new Chinesenumber ();
echo $c->parsenumber (6352);
?>
Turn a financial aspect of a commonly used digital amount into a Chinese character Capital amount PHP class