Convert Arabic numerals to Chinese written numerals

Source: Internet
Author: User

A few days ago someone in the group wrote this, as if quite tangled in the appearance, he helped him write a.

The main idea is that the Chinese digital reading method is four-bit four-bit, high-level digital reading is XXXX million XXXX million xxxx.

voidStart () {//test DataDebug.Log (Full_toword (987654321) );D Ebug. Log (Full_toword (907654321) );D Ebug. Log (Full_toword (9000900654321) );D Ebug. Log (Full_toword (9000900000000));}stringFull_toword (Longi) {Long[] A=New Long[4];//enter numbers in trillions of megabytesA0] = i/1000000000000; a [1] = I/100000000%10000; a [2] = I/10000%10000; a [3] = i%10000;string[] s =New string[4];//string corresponding to each 4-digit numbers [0] = Thousand_toword ((intA0],"trillion"); s [1] = Thousand_toword ((intA1],"billion"); s [2] = Thousand_toword ((intA2],"million"); s [3] = Thousand_toword ((intA3],""); for(intj =0; J <4; J + +) {if(0==a [j]) s [j]="";//Remove High 0Else Break;} for(intj =3; J >=0; j--) {if(0==a [j]) s [j]="";//Remove Low 0Else Break;}intMax//get the largest unit in a number for(max =0; Max <4; max++) {if(A [max]! =0) Break;} for(intj = max +1; J <4; J + +) {if((0! = a [j]) && (a [j]/ +==0)) s [j]="0"+ S [j];//if the four-digit number is not 0 and is not the highest, then add a 0 in front}string_out = s[0]+s[1]+s[2]+s[3];return_out;}///output four-digit reading methodstringThousand_toword (intIstringSS) {int[] A=New int[4];a [0] = I/ +; a [1] = I/ -%Ten; a [2] = I/Ten%Ten; a [3] = i%Ten;string[] s =New string[4];s [0] = Toword (A [0],"thousand"); s [1] = Toword (A [1],"Hundred"); s [2] = Toword (A [2],"10"); s [3] = Toword (A [3],""); for(intj =0; J <4; J + +) {if(0==a [j]) s [j]="";//Remove High 0Else Break;} for(intj =3; J >=0; j--) {if(0==a [j]) s [j]="";//Remove Low 0Else Break;} for(intj =0; J <3; J + +) {if(("0"= = s [j]) && ("0"= = S [j+1])) s [j]="";//Merge the successive 0 into one, such as a number 1001}string_out = s[0]+s[1]+s[2]+s[3]+SS;return_out;}//converts a corresponding Arabic numeral to a Chinese characterstringToword (intIstrings) {Switch(i) { Case 0:return("0"); Case 1:return("a"+s); Case 2:return("two"+s); Case 3:return("three"+s); Case 4:return("Four"+s); Case 5:return("Five"+s); Case 6:return("Six"+s); Case 7:return("Seven"+s); Case 8:return("Eight"+s); Case 9:return("Nine"+s);default: return("");}}}

With a single output, no problem.

Convert Arabic numerals to Chinese written numerals

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.