Arabic numerals to Chinese large (small) written functions

Source: Internet
Author: User
Tags array functions return
function |
chinese_money.php
Changing Arab money num to Chinese money num
/*======================

Functions List:

Chinese_money_max ()
Before the decimal point
This function can be used individually to convert Arabic numerals to Chinese digits (uppercase and lowercase, default to upper case)
Integers only (both positive and negative)

Chinese_money_min ()
After the decimal point is processed

Chinese_money ()

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


function Chinese_money_max ($i, $s =1) {
$c _digit_min = Array ("0", "ten", "Hundred", "thousand", "million", "billion", "trillion");
$c _num_min = Array ("0", "one", "two", "three", "four", "five", "six", "seven", "eight", "Nine", "ten");

$c _digit_max = Array ("0", "Pick Up", "Bai", "Qian", "million", "billion", "trillion");
$c _num_max = Array ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "Nine", "Pick up");

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 <0)
Return "negative". Chinese_money_max (-$i);
if ($i < 11)
return $c _num[$i];
if ($i < 20)
Return $c _num[1]. $c _digit[1]. $c _num[$i-10];
if ($i < 100) {
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 < 1000) {
if ($i% 100 = 0)
return $c _num[$i/100]. $c _digit[2];
else if ($i% < 10)
return $c _num[$i/100]. $c _digit[2]. $c _num[0]. Chinese_money_max ($i% 100);
else if ($i% < 10)
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 < 10000) {
if ($i% 1000 = 0)
return $c _num[$i/1000]. $c _digit[3];
else if ($i% 1000 < 100)
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 < 100000000) {
if ($i% 10000 = 0)
Return Chinese_money_max ($i/10000). $c _digit[4];
else if ($i% 10000 < 1000)
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 < 1000000000000) {
if ($i% 100000000 = 0)
Return Chinese_money_max ($i/100000000). $c _digit[5];
else if ($i% 100000000 < 1000000)
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 < 100000000)
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 ("0", "one", "two", "three", "four", "five", "six", "seven", "eight", "Nine", "ten");
if ($a <10)
Return $c _num[0]. "Horn". $c _num[$a]. "Cent";
else if ($a%10 = 0)
return $c _num[$a/10]. "Horn". $c _num[0]. "Cent";
Else
return $c _num[floor ($a/10)]. "Horn". $c _num[$a%10]. " Points ";
}



function Chinese_money ($i) {
$j =floor ($i);
$x = ($i-$j) *100;
return $x;
Return Chinese_money_max ($j). " Yuan ". Chinese_money_min ($x). " Whole ";
}



The following Code is testing the functions:
/*
if ($_submit== ' go ')
Echo Chinese_money ($e _money);


echo "<form action= ' method=post>";
echo "<input type=text Name=e_money size=20>";
echo "<input type=submit name=_submit value= ' Go ' >";

echo "</form>";
*/
?>


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.