Arabic numerals to Chinese

Source: Internet
Author: User
: This article describes how to convert Arabic numerals into Chinese. For more information about PHP tutorials, see. I haven't written it for a long time. Recently, I used a function implementation to convert the financial amount from numbers to Chinese, and recorded the following:

Class MoneyConstConfig {/*** ing of numbers in Chinese */public static $ NUM_CH_MAP = array (0 => '0', 1 => 'yi ', 2 => 'ER', 3 => 'san', 4 => 'ta', 5 => 'wu', 6 => 'L ', 7 => 'hangzhou', 8 => 'hangzhou', 9 => 'hangzhou ',); /*** amount level Chinese ing */public static $ FINANCE_UNIT_MAP = array (0 => 'shard', 1 => 'angular ', 2 => 'Circle ', 3 => 'start', 4 => 'start', 5 => 'start', 6 => 'wan', 7 => 'start ', 8 => 'Taobao', 9 => 'Taobao', 10 => 'yi', 11 => 'Taobao ',);}

 '', // Tens of thousands * '8' =>'', // hundreds of thousands * '7' => '', // ten thousand * '6' => '', // ten thousand * '5' =>'', // then * '4' => '', // token * '3' => '', // pick up * '2' =>'', // circle * '1' => '', // angle * '0' => '', // minute *); */public static function ticketFinanceChDesc ($ sourceNum) [67/1580] {$ sourceNum = number_format ($ sourceNum, 2 ,'. ', ''); // ensure that the amount is accurate to the minute $ numArr = self: parseNumToArr ($ sourceNum); if (false! = ($ Key = array_search ('. ', $ numArr) {unset ($ numArr [$ key]);} $ rnumArr = array_reverse ($ numArr); $ data = array (); $ I = 0; foreach ($ rnumArr as $ num) {$ data [$ I ++] = $ num;} if ($ I <self: MAX_FINANCE_LEN) {$ data [] = self:: FINANCE_SYMBOL;} $ data = array_pad ($ data, self: MAX_FINANCE_LEN, ''); // use a null character to hold a large position. $ result = array_reverse ($ data ); return $ result;} [43/1580]/*** financeNumToCh ** @ param Double $ sourceNum * @ static * @ access public * @ return string $ chAmount */public static function financeNumToCh ($ sourceNum) {$ sourceNum = number_format ($ sourceNum, 2 ,'. ', ''); // ensure that the amount is accurate to the minute $ numArr = self: parseNumToArr ($ sourceNum); if (false! = ($ Key = array_search ('. ', $ numArr) {unset ($ numArr [$ key]);} $ amount = array (); $ numArrRev = array_reverse ($ numArr); $ I = 0; foreach ($ numArrRev as $ num) {$ amount [$ I ++] = $ num;} $ amount = array_reverse ($ amount, true ); // Here, the re-reversal aims to ensure the key order $ chAmount = self: convertNumArrToChStr ($ amount); return $ chAmount ;} /** [15/1580] * convertNumArrToChStr converts the number array to a Chinese array ** @ param array $ numArr the number array to be converted * @ Static * @ access public * @ return string $ chStr */public static function convertNumArrToChStr ($ numArr) {$ data = array (); $ exists0 = false; // whether 0 $ chStr = ''exists; $ unitMap = array_flip (MoneyConstConfig: $ FINANCE_UNIT_MAP); $ yuan = $ unitMap [self: YUAN_POINT]; $ wan = $ unitMap [self: WAN_POINT]; $ yi = $ unitMap [self: YI_POINT]; foreach ($ numArr as $ key => $ num) {if ($ num! = 0) {if ($ exists0 = true) {$ chStr. = '0'; $ exists0 = false;} $ chStr. = MoneyConstConfig: $ NUM_CH_MAP [$ num]. moneyConstConfig: $ FINANCE_UNIT_MAP [$ key];} else {$ exists0 = true;} if ($ key = $ yuan) {$ chStr = rtrim ($ chStr, self :: YUAN_POINT); $ chStr. = self: YUAN_POINT;} elseif ($ key = $ wan) {$ chStr = rtrim ($ chStr, self: WAN_POINT); $ chStr. = self: WAN_POINT;} elseif ($ key = $ yi) {$ chStr = rtrim ($ chStr, self: YI_POINT); $ chStr. = self: YI_POINT;} return $ chStr ;}}

The above introduces Arabic numerals to Chinese, including some content. I hope my friends who are interested in PHP tutorials can help me.

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.