This article mainly introduces php Arabic numerals to the Chinese capital amount, and shares two implementation methods, if you are interested, you can refer to the example in this article to share the implementation code of converting php Arabic numerals into Chinese RMB capital for your reference. the specific code is as follows:
Code 1: php Arabic numerals are converted to Chinese characters in uppercase, with detailed comments
/*** Function for converting the numeric amount to the Chinese capital amount * String Int $ num the lowercase number to be converted or the lowercase String * return uppercase letter * **/function num_to_ RMB ($ num) {$ c1 = ""; $ c2 = ""; // no more accurate to the end of the minute, so leave only two decimal places $ num = round ($ num, 2); // Convert the number to an integer $ num = $ num * 100; if (strlen ($ num)> 10) {return "The amount is too large. Please check" ;}$ I = 0; $ c = ""; while (1) {if ($ I = 0) {// Obtain the last digit $ n = substr ($ num, strlen ($ num)-1, 1);} else {$ n = $ num % 10 ;} // Convert the last digit to Chinese every time. $ 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; // remove the last digit from the number $ num = $ num/10; $ num = (int) $ num; // end loop if ($ num = 0) {break ;}}$ j = 0; $ slen = strlen ($ c); while ($ j <$ slen) {// utf8 a Chinese character is equivalent to 3 characters $ m = substr ($ c, $ j, 6); // process many numbers with 0 values, remove a Chinese character "zero" if ($ m = 'zero meta' | $ m = '000000' | $ m = '000000' | $ m = 'zero ID ') {$ left = substr ($ c, 0, $ j); $ right = substr ($ c, $ j + 3); $ c = $ left. $ right; $ j = $ J-3; $ slen = $ slen-3;} $ j = $ j + 3 ;} // This is to remove the last "zero" word like 23.0 if (substr ($ c, strlen ($ c)-3, 3) = '0 ') {$ c = substr ($ c, 0, strlen ($ c)-3);} // add the processed Chinese characters to an integer if (empty ($ c )) {return "zero yuan";} else {return $ c. "whole" ;}} echo num_to_ RMB (23000000.00); // tens of thousands of RMB
Code 2: php Arabic numerals converted to Chinese capital
// Function NumToCNMoney ($ num, $ mode = true, $ sim = true) {if (! Is_numeric ($ num) return 'contains non-decimal characters! '; $ Char = $ sim? Array ('0', '1', '2', '3', '4', '5', '6', '7', '8 ', '9'): array ('0', 'yi', 'er', 'san', 'siz', 'wu', 'Lu', 'region ', 'authorization', 'authorization'); $ unit = $ sim? Array ('', '10', '100', '100','', '100', '000000'): array ('', 'pick', 'handler', 'handler', ', 'handler', 'handler'); $ retval = $ mode? 'Meta': 'point'; // if (strpos ($ num ,'. ') {list ($ num, $ dec) = explode ('. ', $ num); $ dec = strval (round ($ dec, 2); if ($ mode) {$ retval. = "{$ char [$ dec ['0']} {$ char [$ dec ['1 ";} else {for ($ I = 0, $ c = strlen ($ dec); $ I <$ c; $ I ++) {$ retval. = $ char [$ dec [$ I] ;}}// integer part $ str = $ mode? Strrev (intval ($ num): strrev ($ num); for ($ I = 0, $ c = strlen ($ str); $ I <$ c; $ I ++) {$ out [$ I] = $ char [$ str [$ I]; if ($ mode) {$ out [$ I]. = $ str [$ I]! = '0 '? $ Unit [$ I % 4]: ''; if ($ I> 1 and $ str [$ I] + $ str [$ i-1] = 0) {$ out [$ I] = '';} if ($ I % 4 = 0) {$ out [$ I]. = $ unit [4 + floor ($ I/4)] ;}}$ retval = join ('', array_reverse ($ out )). $ retval; return $ retval;} echo (NumToCNMoney (2.55 )."
"); Echo (NumToCNMoney (2.55 )."
"); Echo (NumToCNMoney (7965 )."
"); Echo (NumToCNMoney (7965,1, 0 )."
"); Echo (NumToCNMoney (155555555.68 )."
"); Echo (NumToCNMoney (155555555.68 )."
"); Echo (NumToCNMoney (0.8888888 )."
"); Echo (NumToCNMoney (0.8888888 )."
"); Echo (NumToCNMoney (99999999999 )."
"); Echo (NumToCNMoney (99999999999,1, 0 )."
");
I hope this article will help you learn php programming.