Efficient RMB amount conversion program PHP version
Release: 2016-07-25 08:43:23
Original
1233 people have browsed it
-
- //PHP version of the program for converting RMB amount to uppercase
- class Ext_Num2Cny{
- static $basical = array(0=>"zero","壹","谰","三", "四","五","鲁","旒","八","九");
- static $advanced=array(1=>"十","百","千");
-
- public static function ParseNumber($number){
- $number=trim($number);
- if ($number>999999999999) return "The number is too large to handle. Sorry!";
- if ($number==0) return "zero";
- if(strpos($number,'.')){
- $number=round($number,2);
- $data=explode(".",$number);
- $data[0 ]=self::int($data[0]);
- $data[1]=self::dec($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.='wan';
- }
- 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.'元';
- }
-
- 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 .='fen';
- $zero_num=true;
- }
- }else{
- if($zero){
- if($zero_num){
- $_chinese=self::$basical[$v];
- }
- } else{
- $_chinese=self::$basical[$v];
- $_chinese.='angle';
- }
- }
- $data=$_chinese.$data;
- }
- return $data;
- }
- }
-
-
Copy code
|
PHP
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31