RMB value to Chinese capital, RMB Chinese capital _php tutorial

Source: Internet
Author: User

RMB value to Chinese capital, RMB Chinese capital


classnum2rmbclass{/** * RMB value to Chinese capital * @author Sunscheung * @time 2015.11.11 * @param string $number value defaults to 0 * @param St Ring $int _unit Currency unit, the default "meta", some may be "round" * @param bool $is _round Whether the decimal is rounded * @param bool $is _extra_zero whether the integer part ends with 0, Number of decimal places to append 0, such as 1960.30, * Some system requires output "one thousand nine hundred Yuan 0 three corners", in fact, "Yi Qian bai lu Yuan San Jiao" is also right * @param bool $dec _to_int whether to let the fractional part carry to a bit, if carry, digit plus 1, decimal 0, * @return string*/     Public Static functionNUM2RMB ($number= 0,$int _unit= ' Yuan ',$is _round=TRUE,$is _extra_zero=FALSE,$dec _to_int=FALSE) {        //cut the number into two segments        $parts=Explode('.',$number, 2); $int=isset($parts[0])?Strval($parts[0]): ' 0 '; $dec=isset($parts[1])?Strval($parts[1]): '; //if more than 2 digits after the decimal point, do not round the direct intercept, otherwise it will be processed        $dec _len=strlen($dec); if(isset($parts[1]) &&$dec _len> 2) {            if($is _round){                if(round(Floatval("0.").$dec), 2) = = 1 &&$dec _to_int){//decimal rounded to digit                    $int=Empty($int)? 1:Strval($parts[0]+1); $dec= 0; }ElseIf(round(Floatval("0.").$dec), 2) = = 1) {//decimals do not carry to digit                    $dec= "99"; }Else{                    $dec=substr(STRRCHR(Strval(round(Floatval("0.").$dec), 2), '. '), 1); Echo $dec; die(' Boss '); }            }Else{                $dec=substr($parts[1], 0, 2); }        }        //When number is 0.001, the amount after the decimal point is 0 yuan        if(Empty($int) &&Empty($dec)) {            return' 0 '; }        //definition        $chs=Array(' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '); $uni=Array(', ' Pick ', ' bai ', ' thousand '); $dec _uni=Array(' Angle ', ' min '); $exp=Array(' ', ' million '); $res= ''; //integer part from right to left         for($i=strlen($int)-1,$k= 0;$i>= 0;$k++) {            $str= ''; //according to Chinese reading and writing habits, every 4 words for a period of conversion, I have been reducing             for($j= 0;$j< 4 &&$i>= 0;$j++,$i--) {                $u=$int{$i} > 0?$uni[$j] : '';//add units after a number other than 0                $str=$chs[$int{$i}] .$u.$str; }            //echo $str. "|". ($k-2). "
"; $str=RTrim($str, ' 0 ');//Remove the end of the 0 $str=Preg_replace("/0+/", "0",$str);//Replace multiple consecutive 0 if(!isset($exp[$k])) { $exp[$k] =$exp[$k-2]. ' Billion ';//Building Units } $u 2=$str!= '' ?$exp[$k] : ''; $res=$str.$u 2.$res; } //if the fractional part is 00 after processing, you need to handle the $dec=RTrim($dec, ' 0 '); //To find the decimal part from left to right if(!Empty($dec)) { $res.=$int _unit; //If you want to append 0 to the integer part with a number ending in 0, some systems have this requirement if($is _extra_zero) { if(substr($int,-1) = = = ' 0 ') { $res. = ' 0 '; } } for($i= 0,$cnt=strlen($dec);$i<$cnt;$i++) { $u=$dec{$i} > 0?$dec _uni[$i] : '';//add units after a number other than 0 $res.=$chs[$dec{$i}] .$u; } $res=RTrim($res, ' 0 ');//Remove the end of the 0 $res=Preg_replace("/0+/", "0",$res);//Replace multiple consecutive 0}Else { $res.=$int _unit. Whole; } return $number< 0? "(negative)".$res:$res; }}//$a = new Num2rmbclass;Echo(NUM2RMBCLASS::NUM2RMB (' 1600020039.9989 ', ' round ',false,false,false));//One Bai and three points in the corner of the restaurant

http://www.bkjia.com/PHPjc/1082223.html www.bkjia.com true http://www.bkjia.com/PHPjc/1082223.html techarticle RMB value to Chinese capital, RMB Chinese Capital class num2rmbclass{*/* * RMB value to Chinese capital * @author Sunscheung * @time 2015.11.11 * @param string $num ber value ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.