In the process of developing a PHP application, it is often encountered to convert the digital amount to the uppercase Chinese characters. This thought that there must be a good PHP function on the Internet. But I found it, I didn't find it. Helpless, I have to do myself. Now take it out and share it with you. I hope that I can change the history of "finding".
Function Num2RMB ($ Num) {file: // Convert the number to the Chinese uppercase function $ C1 = "Zero 壹 贰 柒捌 柒捌"; $ C2 = "Personal angle picker Pick up 100 million; $ Num = Round ($ Num, 2); $ Num = $ Num * 100; if (Strlen ($ Num)> 10) {Return "OH, Sorry, The Number IS TOON!"; } $ 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 ==0 million || $ P2 == '10)) {$ 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 J <$ m = substr ($ C, $ J, 4); if ($ m == 'zero "|| $ m ==' 万 '|| $ m ==' 亿 ' || $ m == 'zero') {$ left = substr ($ C, 0, $ J); $ Right = Substr ($ C, $ J 2); $ c = $ l r $ right; $ j = $ j-2; $ slen = $ slen-2;} $ j = $ j 2;} if (SubStr ($ C, Strlen ($ C) -2, 2) == 'zero') {$ 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;?>
What is good? Please contact me (cyman20@sina.com).