PHP renminbi amount to capitalization instance code, PHP capital case
PHP renminbi amount to capitalization, the essence is the number converted to Chinese capital, test a bit, very interesting, casually lose a number, you can print out its uppercase, beginner friends try It
PHP RMB amount to uppercase class ext_num2cny{static $basical = Array (0=> "0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU"); Static $advanced =array (1=> "Pick", "Bai", "Qian"); public static function Parsenumber ($number) {$number =trim ($number); if ($number >999999999999) return "The number is too large to handle. I'm sorry! "; 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). ' The 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 '; 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.= ' points '; $zero _num=true; }}else{if ($zero) {if ($zero _num) {$_chinese=self:: $basical [$v]; }}else{$_chinese=self:: $basical [$v]; $_chinese.= ' Corner '; }} $data =$_chinese. $data; } return $data; }}//use method $nun = new Ext_num2cny (); echo EXT_NUM2CNY::P arsenumber (1234567.5);
results: One Bai and three hundred thousand Wu Wu Bai lu qi yuan
I hope this article is helpful for you to learn PHP programming,
http://www.bkjia.com/PHPjc/1058154.html www.bkjia.com true http://www.bkjia.com/PHPjc/1058154.html techarticle PHP renminbi amount to capitalize instance code, PHP Capital instance PHP renminbi capitalization, its essence is the number converted into Chinese capital, tested a bit, very interesting, casually lose ...