Tutorial on converting RMB value to Chinese capital and RMB Chinese capital _ PHP

Source: Internet
Author: User
The RMB value is converted to the Chinese capital and the Chinese capital. The renminbi value is converted to Chinese capital, and the renminbi Chinese capital classNum2RmbClass {*** the renminbi value is converted to Chinese capital * @ authorSunsCheung * @ time2015.11.11 * @ paramstring $ number the renminbi value is converted to Chinese capital, and the renminbi is capitalized.
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; }}// $ a = new Num2RmbClass; echo (Num2RmbClass: num2rmb ('2017. 1600020039. 9989 ', 'Circle', false); // You can view the points of a circle.

Invalid class Num2RmbClass {/*** convert the renminbi value to Chinese capital * @ author SunsCheung * @ time 2015.11.11 * @ param string $ number value...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.