PHP function for converting numeric amount to Chinese capital amount
- /**
- * Function for converting a numeric amount to a Chinese capital amount
- * String Int $ num the lowercase number or lowercase String to be converted
- * Return uppercase letters
- * Two decimal places
- **/
- Function get_amount ($ num ){
- $ C1 = "";
- $ C2 = "yuanqibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaibaiyi ";
- $ Num = round ($ num, 2 );
- $ Num = $ num * 100;
- If (strlen ($ num)> 10 ){
- Return "the data is too long. if you don't have the money, check ";
- }
- $ I = 0;
- $ C = "";
- While (1 ){
- If ($ I = 0 ){
- $ N = substr ($ num, strlen ($ num)-1, 1 );
- } Else {
- $ N = $ num % 10;
- }
- $ P1 = substr ($ c1, 3 * $ n, 3 );
- $ P2 = substr ($ c2, 3 * $ I, 3 );
- If ($ n! = '0' | ($ n = '0' & ($ p2 = '000000' | $ p2 = '000000' | $ p2 =' yuan '))) {
- $ C = $ p1. $ p2. $ c;
- } Else {
- $ C = $ p1. $ c;
- }
- $ I = $ I + 1;
- $ Num = $ num/10;
- $ Num = (int) $ num;
- If ($ num = 0 ){
- Break;
- }
- }
- $ J = 0;
- $ Slen = strlen ($ c );
- While ($ j <$ slen ){
- $ M = substr ($ c, $ j, 6 );
- If ($ m = 'zero meta' | $ m = '000000' | $ m = '000000' | $ m = 'zero-zero '){
- $ Left = substr ($ c, 0, $ j );
- $ Right = substr ($ c, $ j + 3 );
- $ C = $ left. $ right;
- $ J = $ J-3;
- $ Slen = $ slen-3;
- }
- $ J = $ j + 3;
- }
- If (substr ($ c, strlen ($ c)-3, 3) = '0 '){
- $ C = substr ($ c, 0, strlen ($ c)-3 );
- }
- If (empty ($ c )){
- Return "zero RMB ";
- } Else {
- Return $ c. "whole ";
- }
- }
|
Convert to, PHP