php代码
<?php class TransFormNumber{
public $chinaData = array('1'=>'壹','2'=>'贰','3'=>'叁','4'=>'肆','5'=>'伍','6'=>'陆','7'=>'柒','8'=>'捌','9'=>'玖');
public $chinaDataInt = array('1'=>'元','2'=>'拾','3'=>'佰','4'=>'仟','5'=>'万','6'=>'拾','7'=>'佰','8'=>'仟','9'=>'亿','10'=>'拾','11'=>'佰','12'=>'仟','13'=>'万');
public $chinaDataFloat = array('1'=>'角','2'=>'分');
private $Intnumber; // string
private $Floatnumber; // string
public $error = array('0'=>'零','def'=>'数据格式不支持');
public function __construct($intnumber,$floatnumber){
$this->Intnumber = $intnumber;
$this->Floatnumber = $floatnumber;
}
/*13位整数*/
public function getTransInt(){
$this->Intnumber = intval($this->Intnumber);
$len = strlen($this->Intnumber);
if($len > 13){
return $this->errorNotice(1);
}
if($this->Intnumber == 0){
return $this->errorNotice('def');
}
$intData = strrev(substr($this->Intnumber,0,$len));
$data = $this->setTransInt($intData,$len);
krsort($data);
$str = rtrim(join($data,''),'零');
if(substr($this->Intnumber,$len-1,1) == 0){
$str.='元';
}
unset($data);
return $str;
}
public function getTransFloat(){
return $this->setTransFloat($this->Floatnumber,strlen($this->Floatnumber));
}
private function setTransInt($intData,$pos){
for($i=0;$ichinaData[$oneData].$this->chinaDataInt[$i+1];
}
}
unset($intData,$oneData,$i);
return $data;
}
//紧支持两位小数
private function setTransFloat($floatData,$pos){
if($pos > 2){
return $this->errorNotice('def');
}
if($floatData{0} == 0){
$data[] = '零';
}else{
$data[] = $this->chinaData[$floatData{0}].$this->chinaDataFloat[1];
}
if($floatData{1} != 0 ){
$data[] = $this->chinaData[$floatData{1}].$this->chinaDataFloat[2];
}
return implode('',$data);
}
public function errorNotice($error){
return $this->error[$error];
}
}
$num = new TransFormNumber('100228030','80');
echo $num->getTransInt();
echo $num->getTransFloat();










