Conversion from numeric amount to Chinese uppercase characters in PHP _ PHP Tutorial

Source: Internet
Author: User
Tags chop
PHP converts the numeric amount to an uppercase Chinese character. During the development of PHP applications, the task of converting the numeric amount to uppercase Chinese characters is often encountered. I thought there must be compiled PHP functions on the Internet. However, when looking for a PHP application, I often encounter the task of converting the numeric amount to uppercase Chinese characters. I thought there must be compiled PHP functions on the Internet. But none of them were found. Helpless, so I had to do it myself. Now let's share it with you. We hope that we can change the history we cannot find.
Function num2rmb ($ num) {file: // function used to convert the numeric amount into an uppercase Chinese number.
$ C1 = "";
$ C2 = "yuanqibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaiyi ";
$ Num = round ($ num, 2 );
$ Num = $ num * 100;
If (strlen ($ num)> 10 ){
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;
}
$ P1 = substr ($ c1, 2 * $ n, 2 );
$ P2 = substr ($ c2, 2 * $ I, 2 );
If ($ n! = 0 | ($ n = 0 & ($ p2 = | $ p2 = | $ p2 = RMB ))){
$ C = $ p1. $ p2. $ c;
} Else {
$ C = $ p1. $ c;
}
$ I = $ I + 1;
$ Num = $ num/10;
$ Num = (int) $ num;
If ($ num = 0 ){
Break;
}
} // End of while | here, we got a chinese string with some useless character
F // we chop out the useless characters to form the correct output
$ J = 0;
$ Slen = strlen ($ c );

While ($ j <$ slen ){
$ M = substr ($ c, $ j, 4 );
If ($ m = 0 RMB | $ m = 0 thousand | $ m = 0 billion | $ m = 0 ){
$ Left = substr ($ c, 0, $ j );
$ Right = substr ($ c, $ j + 2 );
$ C = $ left. $ right;
$ J = $ J-2;
$ Slen = $ slen-2;
}
$ J = $ j + 2;
}
If (substr ($ c, strlen ($ c)-2, 2) = 0 ){
$ C = substr ($ c, 0, strlen ($ c)-2 );
} // If there is a 0 on the end, chop it out
Return $ c. "whole ";
} // End of function
?>
$ Out = num2rmb (1001.4570 );
Echo $ out;
?>
If you have any good comments, please contact me (cyman20@sina.com ).

Bytes. I thought there must be compiled PHP functions on the Internet. But there is no...

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.