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. But none of them were found. Helpless, so I had to do it myself. Now let's share it with you. Hope to change "find" SyntaxHighlighter. all ();
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. 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 ).