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

函数|中文


//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 "
";
*/
?>



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.