PHP lowercase number to the capital number of the function of the yuan

Source: Internet
Author: User
RMB Digital to Chinese capital, is a more common demand, so here to share a function, also counted as a record, in case you will use later!

function Num2rmb ($num) {$c 1 = "0 One and three Woolu qi Ba Jiu";    $c 2 = "split-angle element pick Bai thousand thousand million";    $num = Round ($num, 2);    $num = $num * 100;    if (strlen ($num) >) {return "oh,sorry,the number is too long!";    } $i = 0;    $c = "";        while (1) {if ($i = = 0) {$n = substr ($num, strlen ($num)-1, 1);        } else {$n = $num% 10;        } $p 1 = substr ($c 1, 3 * $n, 3);        $p 2 = substr ($c 2, 3 * $i, 3); 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;        $num = $num/10;        $num = (int) $num;        if ($num = = 0) {break;    }} $j = 0;        $slen = strlen ($c);        while ($j < $slen) {$m = substr ($c, $j, 6);            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;    } if (substr ($c, strlen ($c)-3, 3) = = ' 0 ') {$c = substr ($c, 0, strlen ($c)-3); }//If there is a ' 0 ' on the end, chop it out return $c. "Whole";}
  • 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.