首页 >php教程 >php手册 >阿拉伯数字转中文大(小)写的函数

阿拉伯数字转中文大(小)写的函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-21 09:12:231471浏览

函数|中文


//chinese_money.php
//Changing Arab Money Num to Chinese Money Num
/*======================

Functions List:

Chinese_Money_Max()
小数点前
此函数可以单独拿出用于将阿拉伯数字转为中文数字(大小写可选,默认为大写)
仅限整数(正负皆可)

Chinese_Money_Min()
处理小数点后

Chinese_Money()

=======================*/


function Chinese_Money_Max($i,$s=1){
    $c_digit_min = array("零","十","百","千","万","亿","兆");
    $c_num_min = array("零","一","二","三","四","五","六","七","八","九","十");
    
    $c_digit_max = array("零","拾","佰","仟","万","亿","兆");
    $c_num_max = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾");
    
    if($s==1){
        $c_digit = $c_digit_max;
        $c_num = $c_num_max;
    }
    else{
        $c_digit = $c_digit_min;
        $c_num = $c_num_min;
    }
    
    if($i        return "负".Chinese_Money_Max(-$i);
    if ($i         return $c_num[$i];
    if ($i         return $c_num[1].$c_digit[1] . $c_num[$i - 10];
    if ($i         if ($i % 10)
            return $c_num[$i / 10] . $c_digit[1] . $c_num[$i % 10];
        else
            return $c_num[$i / 10] . $c_digit[1];
    }
    if ($i         if ($i % 100 == 0)
            return $c_num[$i / 100] . $c_digit[2];
        else if ($i % 100             return $c_num[$i / 100] . $c_digit[2] . $c_num[0] . Chinese_Money_Max($i % 100);
        else if ($i % 100             return $c_num[$i / 100] . $c_digit[2] . $c_num[1] . Chinese_Money_Max($i % 100);
        else
            return $c_num[$i / 100] . $c_digit[2] . Chinese_Money_Max($i % 100);
    }
    if ($i         if ($i % 1000 == 0)
            return $c_num[$i / 1000] . $c_digit[3];
        else if ($i % 1000             return $c_num[$i / 1000] . $c_digit[3] . $c_num[0] . Chinese_Money_Max($i % 1000);
        else
            return $c_num[$i / 1000] . $c_digit[3] . Chinese_Money_Max($i % 1000);
    }
    if ($i         if ($i % 10000 == 0)
            return Chinese_Money_Max($i / 10000) . $c_digit[4];
        else if ($i % 10000             return Chinese_Money_Max($i / 10000) . $c_digit[4] . $c_num[0] . Chinese_Money_Max($i % 10000);
        else
            return Chinese_Money_Max($i / 10000) . $c_digit[4] . Chinese_Money_Max($i % 10000);
    }
    if ($i         if ($i % 100000000 == 0)
            return Chinese_Money_Max($i / 100000000) . $c_digit[5];
        else if ($i % 100000000             return Chinese_Money_Max($i / 100000000) . $c_digit[5] . $c_num[0] . Chinese_Money_Max($i % 100000000);
        else
            return Chinese_Money_Max($i / 100000000) . $c_digit[5] . Chinese_Money_Max($i % 100000000);
    }
    if ($i % 1000000000000 == 0)
        return Chinese_Money_Max($i / 1000000000000) . $c_digit[6];
    else if ($i % 1000000000000         return Chinese_Money_Max($i / 1000000000000) . $c_digit[6] . $c_num[0] . Chinese_Money_Max($i % 1000000000000);
    else
        return Chinese_Money_Max($i / 1000000000000) . $c_digit[6] . Chinese_Money_Max($i % 1000000000000);
}

function Chinese_Money_Min($a){
    $c_num = array("零","一","二","三","四","五","六","七","八","九","十");
    if($a        return $c_num[0] . "角" . $c_num[$a] . "分";
    else if($a%10 == 0)
        return $c_num[$a/10] . "角" . $c_num[0] . "分";
    else
        return $c_num[floor($a/10)] . "角" . $c_num[$a%10] ."分";
}



function Chinese_Money($i){
    $j=Floor($i);
    $x=($i-$j)*100;
    //return $x;
    return Chinese_Money_Max($j)."元".Chinese_Money_Min($x)."整";
}



//The Following Code is Testing The Functions:
/*
if($_submit=='Go')
    echo Chinese_Money($e_money);


echo "

";
echo "";
echo "";

echo "
";
*/
?>



声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn