PHP类-人民币金额转大写

不言
发布: 2023-03-24 16:48:01
原创
1266 人浏览过

这篇文章介绍的内容是关于PHP类-人民币金额转大写,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

<?php
//人民币金额转大写程序PHP版
class Ext_Num2Cny{
    static $basical = array(0=>"零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
    static $advanced=array(1=>"拾","佰","仟");

    public static function ParseNumber($number){
        $number=trim($number);
        if ($number>999999999999) return "数字太大,无法处理。抱歉!";
        if ($number==0) return "零";
        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).'整';
        }
    }

    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.='亿';
                    }elseif($k==4){
                        $_chinese.='万';
                    }
                    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.=&#39;0&#39;;
        $arr=array_reverse(str_split($number));
        $data=&#39;&#39;;
        $zero_num=false;
        foreach ($arr as $k=>$v){
            $zero=($v==0)?true:false;
            $_chinese='';
            if($k==0){
                if(!$zero){
                    $_chinese=self::$basical[$v];
                    $_chinese.='分';
                    $zero_num=true;
                }
            }else{
                if($zero){
                    if($zero_num){
                        $_chinese=self::$basical[$v];
                    }
                }else{
                    $_chinese=self::$basical[$v];
                    $_chinese.='角';
                }
            }
            $data=$_chinese.$data;
        }
        return $data;
    }
}
登录后复制

相关推荐:

汉字与拼音转换PHP类


           


以上是PHP类-人民币金额转大写的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板