Php converts the encapsulated RMB value to the Chinese capital type ,. Php-encapsulated renminbi values are converted to Chinese capital classes, php-encapsulated renminbi value to Chinese capital class classNum2RmbClass {*** renminbi value to Chinese capital * @ authorSunsCheung * php-encapsulated renminbi value to Chinese capital class,
Convert the encapsulated RMB value in php to the Chinese capital type
Class Num2RmbClass {/*** convert the renminbi value to Chinese capital * @ author SunsCheung * @ time 2015.11.11 * @ param string $ number. the default value is 0 * @ param string $ int_unit, the default value is "RMB". some requirements may be "circle" * @ param bool $ is_round: whether to round decimal places * @ param bool $ is_extra_zero: whether to end the integer part with 0, add 0 to the number in the decimal place, for example, 1960.30. * Some systems need to output "", in fact, "" is also true * @ param bool $ dec_to_int whether to enable the fractional part to carry to a single digit. if the carry part is added with 1, the decimal point is 0, * @ return string */public static function num2 RMB ($ number = 0, $ int_unit = 'meta', $ is_round = TRUE, $ is_extra_zero = FALSE, $ dec_to_int = FALSE) {// split the number into two segments $ parts = explode ('. ', $ number, 2); $ int = isset ($ parts [0])? Strval ($ parts [0]): '0'; $ dec = isset ($ parts [1])? Strval ($ parts [1]): ''; // if there are more than two digits after the decimal point, it will be intercepted without rounding. otherwise, $ dec_len = strlen ($ dec) will be processed ); if (isset ($ parts [1]) & $ dec_len> 2) {if ($ is_round) {if (round (floatval ("0. ". $ dec), 2) = 1 & $ dec_to_int) {// decimal places to a single position $ int = empty ($ int )? 1: strval ($ parts [0] + 1); $ dec = 0;} elseif (round (floatval ("0. ". $ dec), 2) = 1) {// decimal places do not carry to a single position $ dec = "99 ";} else {$ dec = substr (strrchr (strval (round (floatval ("0. ". $ dec), 2 )),'. '), 1); echo $ dec; die ('boss') ;}} else {$ dec = substr ($ parts [1], 0, 2 );}} // when number is 0.001, the decimal point is 0 RMB if (empty ($ int) & empty ($ dec) {return '0 ';} // Define $ chs = array ('0', 'yi', 'er', 'san', 'siz', 'wu', 'Lu', 'region ', 'authorization', 'authorization'); $ uni = array ('', 'Pick', 'hangzhou', 'hangzhou'); $ dec_uni = array ('angular ', 'shard'); $ exp = array ('', 'wan'); $ res = ''; // right-to-left search for the integer ($ I = strlen ($ int)-1, $ k = 0; $ I> = 0; $ k ++) {$ str = ''; // converts each 4 words into a segment based on Chinese reading and writing habits, I have been reducing for ($ j = 0; $ j <4 & $ I> = 0; $ j ++, $ I --) {$ u = $ int {$ I}> 0? $ Uni [$ j]: ''; // add a unit after a number other than 0 $ str = $ chs [$ int {$ I}]. $ u. $ str;} // echo $ str. "| ". ($ k-2 )."
"; $ Str = rtrim ($ str, '0'); // remove the 0 $ str = preg_replace ("/0 +/"," 0 ", $ str); // replace multiple consecutive 0 if (! Isset ($ exp [$ k]) {$ exp [$ k] = $ exp [$ k-2]. 'yi'; // Construction Unit} $ u2 = $ str! = ''? $ Exp [$ k]: ''; $ res = $ str. $ u2. $ res;} // if the decimal part is 00 after processing, you need to process $ dec = rtrim ($ dec, '0 '); // find if (! Empty ($ dec) {$ res. = $ int_unit; // whether to append 0 to the number ending with 0 in the integer part. some systems require that if ($ is_extra_zero) {if (substr ($ int, -1) = '0') {$ res. = '0' ;}}for ($ I = 0, $ cnt = strlen ($ dec); $ I <$ cnt; $ I ++) {$ u = $ dec {$ I}> 0? $ Dec_uni [$ I]: ''; // add the unit $ res after a number other than 0. = $ chs [$ dec {$ I}]. $ u ;}$ res = rtrim ($ res, '0'); // Remove 0 $ res = preg_replace ("/0 +/", "0 ", $ res); // replace multiple consecutive 0} else {$ res. = $ int_unit. 'Round ';} return $ number <0? "(Negative)". $ res: $ res ;}}
Usage
// $ A = new Num2RmbClass; echo (Num2RmbClass: num2rmb ('192. 100', 'Circle ', false ));
Let's share with you a simple one.
Function cny ($ ns) {static $ cnums = array ("zero", "one", "two", "three", "si", "Wu ", "Land", "hour"), $ cnyunits = array ("circle", "corner", "minute "), $ grees = array ("pick", "weight", "weight", "", "pick", "weight", "weight "); list ($ ns1, $ NS2.) = explode (". ", $ ns, 2); $ ns_filter (array ($ ns2 [1], $ ns2 [0]); $ ret = array_merge ($ NS2, array (implode ("", _ cny_map_unit (str_split ($ ns1), $ grees), ""); $ ret = implode ("", array_reverse (_ cny_map_unit ($ ret, $ cnyunits ))); Return str_replace (array_keys ($ cnums), $ cnums, $ ret);} function _ cny_map_unit ($ list, $ units) {$ ul = count ($ units ); $ xs = array (); foreach (array_reverse ($ list) as $ x) {$ l = count ($ xs); if ($ x! = "0" |! ($ L % 4) {$ n = ($ x = '0 '? '': $ X). ($ units [(L-1) % $ ul]);} else {$ n = is_numeric ($ xs [0] [0])? $ X: '';} array_unshift ($ xs, $ n);} return $ xs;} $ value = '2017. 04 '; print cny ($ value); echo ''; output:
Another netizen is doing well.
/*** 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
Articles you may be interested in:
- Use C # to convert Arabic numerals to uppercase Chinese
- JavaScript dynamically converts the numeric amount to the Chinese capital amount
- PHP function code for converting RMB into uppercase letters
- JavaScript code example for converting Arabic numerals into Chinese capital
- Php converts the amount into uppercase letters
Convert, php encapsulated renminbi value to Chinese capital class Num2RmbClass {/*** convert renminbi value to Chinese capital * @ author SunsCheung *...