The occasional encounter in the work of the need to convert the amount of renminbi, that is, Arabic numerals into uppercase characters, the following is the author's practice summed up the method, and hereby record to prevent the memo.
Class num2cny{static $basical =array (0=> ' 0 ', ' one ', ' II ', ' San ', ' Restaurant ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU ');
Static $advanced =array (1=> ' pick ', ' bai ', ' thousand ');
public static function Parsenumber ($number) {$number =trim ($number);
if (!is_numeric ($number) intval ($number) >999999999999) return ' error ';
if ($number ==0) return ' 0 '; if (Strpos ($number, '. '))
{$number =round ($number, 2);
$data =explode ('. ', $number);
$data [0]=self::int ($data [0]);
$data [1]=self::d EC ($data [1]);
return $data [0]. $data [1]; }else{return Self::int ($number). '
Whole ';
public static function int ($number) {$arr =array_reverse (Str_split ($number));
$data = ';
$zero =false;
$zero _num=0;
foreach ($arr as $k => $v) {$_chinese= ';
$zero = ($v ==0) True:false;
$x = $k% 4;
if ($x && $zero && $zero _num>1) continue;
Switch ($x) {case 0:if ($zero) {$zero _num=0; }else{$_chinese=self:: $basical [$V];
$zero _num=1;
if ($k ==8) {$_chinese.= ' billion ';
}elseif ($k ==4) {$_chinese.= ' million ';
} break;
Default:if ($zero) {if ($zero _num==1) {$_chinese=self:: $basical [$v];
$zero _num++;
}else{$_chinese=self:: $basical [$v];
$_chinese.=self:: $advanced [$x];
}} $data =$_chinese. $data;
return $data. ' Yuan ';
The public static function Dec ($number) {if (strlen ($number) <2) $number. = ' 0 ';
$arr =array_reverse (Str_split ($number));
$data = ';
$zero _num=false;
foreach ($arr as $k => $v) {$zero = ($v ==0)? True:false;
$_chinese= ';
if ($k ==0) {if (! $zero) {$_chinese=self:: $basical [$v];
$_chinese.= ' min ';
$zero _num=true;
}}else{if ($zero) {if ($zero _num) {$_chinese=self:: $basical [$v]; }else{$_chinese=self:: $basical [$v];
$_chinese.= ' horn ';
}} $data =$_chinese. $data;
return $data; }
}
The use process is also simple, as follows:
echo NUM2CNY::P arsenumber (1234567.5);//www.alixixi.com
The result will be output:
I found three thousand million land to pick up seven Yuan Wu Jiao
Another explanation is that if you only need to convert Arabic numerals to uppercase, you can refer to this site article:
PHP converts Arabic numerals into Chinese character functions