Convert PHP digital amount to Chinese capital amount function number to Chinese

Source: Internet
Author: User

/** * The function of converting a digital amount to a Chinese capital amount *string Int $num the lowercase or lowercase string to convert *return capital Letter * Decimal place is two bits **/functionNUM_TO_RMB ($num){    $c 1= "0 One and three Woolu qi Ba Jiu"; $c 2= "Split-angle element pick Bai thousand thousand thousand Million"; //you don't have to be accurate to the point, so just two decimal digits left.    $num=round($num, 2); //Convert a number to an integer    $num=$num* 100; if(strlen($num) > 10) {        return"The amount is too large, please check"; }     $i= 0; $c= "";  while(1) {        if($i= = 0) {            //Get last digit            $n=substr($num,strlen($num)-1, 1); } Else {            $n=$num% 10; }        //convert the last digit to Chinese each time        $p 1=substr($c 1, 3 *$n-R); $p 2=substr($c 2, 3 *$i-R); if($n! = ' 0 ' | | ($n= = ' 0 ' && ($p 2= = ' billion ' | |$p 2= = ' million ' | |$p 2= = ' Yuan '))) {            $c=$p 1.$p 2.$c; } Else {            $c=$p 1.$c; }        $i=$i+ 1; //minus the last digit.        $num=$num/10; $num= (int)$num; //End Loop        if($num= = 0) {             Break; }     }    $j= 0; $slen=strlen($c);  while($j<$slen) {        //UTF8 a kanji equivalent to 3 characters        $m=substr($c,$j, 6); //deal with a lot of 0 of the numbers, each time the loop removes a kanji "0"        if($m= = ' 0 Yuan ' | |$m= = ' 0 ' | |$m= = ' 0 ' | |$m= = ' 00 ') {            $left=substr($c, 0,$j); $right=substr($c,$j+ 3); $c=$left.$right; $j=$j-3; $slen=$slen-3; }         $j=$j+ 3; }     //this is to get rid of the last "0" word like 23.0.    if(substr($c,strlen($c)-3, 3) = = ' 0 ') {        $c=substr($c, 0,strlen($c)-3); }    //Add the processed Chinese characters to the "whole"    if(Empty($c)) {        return"0 yuan Whole"; }Else{        return $c. Whole; }}EchoNUM_TO_RMB (0.45);

Convert PHP digital amount to Chinese capital amount function number to Chinese

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.