<? Php /** * Lowercase to uppercase * * @ Param string $ number value * @ Param string $ int_unit currency unit. The default value is "RMB". Some requirements may be "RMB" * @ Param bool $ is_round: whether to round the decimal number * @ Param bool $ is_extra_zero: whether to end the integer with 0, and add 0 to the decimal number, such as 1960.30, * Some systems require the output of "one hacker, and one hacker". * @ Return string * @ Site www.111cn.net */ Function num2rmb ($ number = 0, $ int_unit = 'meta', $ is_round = TRUE, $ is_extra_zero = FALSE) { // Split the number into two segments $ Parts = <A class = infotextkey href = "http: // www." target = _ blank> explode </A> ('.', $ number, 2 ); $ Int = <A class = infotextkey href = "http://www.111cn.net/" target = _ blank> isset </A> ($ 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 directly without rounding. Otherwise, it will be processed. $ Dec_len = strlen ($ dec ); If (isset ($ parts [1]) & $ dec_len> 2) { $ Dec = $ is_round ? Substr (strrchr (strval (round (floatval ("0.". $ dec), 2), '.'), 1) : Substr ($ parts [1], 0, 2 ); } // When number is 0.001, the amount after the decimal point is 0 yuan If (empty ($ int) & empty ($ dec )) { Return '0 '; } // Define $ Chs = array ('0', 'yi', 'er', 'san', 'siz', 'wu', 'L', 'region ', 'authorization', 'authorization '); $ Uni = array ('', 'pick', 'handler', 'handler '); $ Dec_uni = array ('angular ', 'shard '); $ Exp = array ('', 'wan '); $ Res = ''; // Locate the integer from the right to the left For ($ I = strlen ($ int)-1, $ k = 0; $ I >=0; $ k ++) { $ Str = ''; // According to the Chinese reading and writing habits, each 4 words is converted into a segment, and I has been decreasing 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). "<br> "; $ Str = rtrim ($ str, '0'); // remove the end 0 $ Str = preg_replace ("/0 +/", "zero", $ str); // replace multiple consecutive 0 If (! Isset ($ exp [$ k]) { $ Exp [$ k] = $ exp [$ k-2]. '100 '; // Build unit } $ U2 = $ str! = ''? $ Exp [$ k]: ''; $ Res = $ str. $ u2. $ res; } // If the decimal part is 00 after processing $ Dec = rtrim ($ dec, '0 '); // Find the fractional part from left to right If (! Empty ($ dec )) { $ Res. = $ int_unit; // Whether to append 0 to the number ending with 0 in the integer part. Some systems have this requirement. 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 a unit after a number other than 0 $ Res. = $ chs [$ dec {$ I}]. $ u; } $ Res = rtrim ($ res, '0'); // remove the end 0 $ Res = preg_replace ("/0 +/", "zero", $ res); // replace multiple consecutive 0 } Else { $ Res. = $ int_unit. 'Integral '; } Return $ res; } Echo "<pre> "; $ Number = "1000000000000000012345678900.501 "; Echo $ number. ":". num2rmb ($ number ); Echo "n "; $ Number = "1960.30 "; Echo $ number. ":". num2rmb ($ number ); Echo "n "; $ Number = "1960.30 "; Echo $ number. ":". num2rmb ($ number, "circle", true, true ); Echo "n "; $ Number = "123456789.005 "; Echo $ number. ":". num2rmb ($ number ); Echo "n "; $ Number = "123456789.005 "; Echo $ number. ":". num2rmb ($ number, "RMB", false ); Echo "n "; $ Number = "10000000000000000060009.101 "; Echo $ number. ":". num2rmb ($ number ); Echo "n "; $ Number = "1680.32 "; Echo $ number. ":". num2rmb ($ number ); ?> |