PHP RMB lowercase to uppercase

<?php
header("charset=utf-8;");

function numTrmb($num){
    $d = array("zero", "one", "two", "three", "four", "wu", "lu", "seven", "eight", "nine");
    $e = array('Yuan', 'Ten thousand', 'Hundred', 'Thousand', 'Ten thousand', 'Ten thousand', 'Billion', 'Thousand', 'Billion', 'Ten Billion', ' Billion', 'Thousand Billion');
    $p = array('point', 'corner');
    $zheng = "整";
    $final = array();
    $inwan = 0;//Whether there are 10,000
    $inyi = 0;//Whether there are billions
    $len = 0;//Length after decimal point
    $y = 0;
    $num = round($num, 2);//Accurate to the minute
    if(strlen($num) > 15){
        return "The amount is too large";
        the();
    }
    if($c = strpos($num, '.')){//There is a decimal point, $c is the number of digits before the decimal point
        $len=strlen($num)-strpos($num,'.')-1;//How many digits after the decimal point
    }else{//No decimal point
        $c = strlen($num);
        $zheng = 'whole';
    }
    for($i = 0; $i < $c; $i++){
        $bit_num = substr($num, $i, 1);
        if ($bit_num != 0 || substr($num, $i + 1, 1) != 0) {
            @$low = $low . $d[$bit_num];
        }
        if ($bit_num || $i == $c - 1) {
            @$low = $low . $e[$c - $i - 1];
        }
    }
    if($len!=1){
        for ($j = $len; $j >= 1; $j--) {
            $point_num = substr($num, strlen($num) - $j, 1);
            @$low = $low . $d[$point_num] . $p[$j - 1];
        }
    }else{
        $point_num = substr($num, strlen($num) - $len, 1);
        $low=$low.$d[$point_num].$p[$len];
    }
    $chinses = str_split($low, 3);//The string is converted to an array
    for ($x = count($chinses) - 1; $x >= 0; $x--) {
        if ($inwan == 0 && $chinses[$x] == $e[4]) {//Filter repeated 10,000
            $final[$y++] = $chinses[$x];
            $ inwan = 1;
        }
        if ($inyi == 0 && $chinses[$x] == $e[8]) {//Filter repeated billions
            $final[$y++] = $chinses[$x];
            $ inyi = 1;
            $ inwan = 0;
        }
        if ($chinses[$x] != $e[4] && $chinses[$x] !== $e[8]) {
            $final[$y++] = $chinses[$x];
        }
    }
    $newstr = (array_reverse($final));
    $nstr = join($newstr);
    if((substr($num, -2, 1) == '0') && (substr($num, -1) <> 0)){
        $nstr = substr($nstr, 0, (strlen($nstr) -6)).'零'. substr($nstr, -6, 6);
    }
    $nstr=(strpos($nstr,'zero angle')) ? substr_replace($nstr,"",strpos($nstr,'zero angle'),6) : $nstr;
    return $nstr = (substr($nstr,-3,3)=='元') ? $nstr . $zheng : $nstr;
}
echo TrmbNumber(965002.65);

 

Effect picture:

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326527636&siteId=291194637