PHP code for converting RMB amount to capital instance, php RMB capital instance _ PHP Tutorial

Source: Internet
Author: User
Tags learn php programming php example
PHP code used to convert the RMB amount to an uppercase instance, and php code used to convert the RMB amount to an uppercase instance. PHP example code for converting the RMB amount to capital, php example for converting the RMB amount to capital, the essence is converting the numbers into Chinese capital. it is interesting to test it, code for converting php RMB amount to capital instance, php RMB capital instance

PHP converts the RMB amount to uppercase, and the essence is to convert the numbers to Chinese uppercase. after testing, it is very interesting. if you enter a number, you can print it in uppercase. just give it a try.

// Convert the php RMB amount to uppercase class Ext_Num2Cny {static $ basical = array (0 => "0", "one", "two", "three", "si ", "Wu", "Lu", "Lu", "Jun", "Jun"); static $ advanced = array (1 => "pick up", "Jun ", "Partition"); public static function ParseNumber ($ number) {$ number = trim ($ number); if ($ number> 999999999999) return "the number is too large to be processed. Sorry! "; If ($ number = 0) return" zero "; if (strpos ($ number ,'. ') {$ number = round ($ number, 2); $ data = explode (". ", $ number); $ data [0] = self: int ($ data [0]); $ data [1] = self :: dec ($ data [1]); return $ data [0]. $ data [1];} else {return self: int ($ number ). 'Round ';}} public static function int ($ number) {$ arr = array_reverse (str_split ($ number); $ data = ''; $ zero = false; $ zero_num = 0; foreach ($ arr as $ k = >$ v) {$ _ chinese = ''; $ zero = ($ v = = 0 )? True: false; $ x = $ k % 4; if ($ x & $ zero & $ zero_num> 1) continue; switch ($ x) {case 0: if ($ zero) {$ zero_num = 0;} else {$ _ chinese = self: $ basical [$ v]; $ zero_num = 1 ;} if ($ k = 8) {$ _ chinese. = 'yi';} elseif ($ k = 4) {$ _ chinese. = 'wan';} break; default: if ($ zero) {if ($ zero_num = 1) {$ _ chinese = self ::$ basical [$ v]; $ zero_num ++ ;}} else {$ _ chinese = self ::$ basical [$ v]; $ _ chinese. = self: $ advanced [$ x] ;}$ data =$ _ chinese. $ da Ta;} return $ data. 'meta';} public static function dec ($ number) {if (strlen ($ number) <2) $ number. = '0'; $ arr = array_reverse (str_split ($ number); $ data = ''; $ zero_num = false; foreach ($ arr as $ k => $ v) {$ zero = ($ v = 0 )? True: false; $ _ chinese = ''; if ($ k = 0) {if (! $ Zero) {$ _ chinese = self: $ basical [$ v]; $ _ chinese. = 'shard'; $ zero_num = true ;}} else {if ($ zero) {if ($ zero_num) {$ _ chinese = self :: $ basical [$ v] ;}} else {$ _ chinese = self ::$ basical [$ v]; $ _ chinese. = 'angular ';}$ data =$ _ chinese. $ data;} return $ data ;}// usage $ nun = new Ext_Num2Cny (); echo Ext_Num2Cny: ParseNumber (1234567.5 );

Result:You can pick up tens of thousands of yuan

I hope this article will help you learn php programming,

PHP converts the RMB amount to uppercase, and the essence is to convert the numbers into Chinese capital. after testing, it is very interesting to lose anything...

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.