/** * Convert Arabic numerals to Chinese numerals */+ (NSString *) Translationarabicnum: (nsinteger) arabicnum{nsstring *arabicnumstr = [NSString Strin gwithformat:@ "%ld", (long) arabicnum]; Nsarray *arabicnumeralsarray = @[@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", @ "0"]; Nsarray *chinesenumeralsarray = @[@ "One", @ "two", @ "three", @ "four", @ "five", @ "six", @ "seven", @ "eight", @ "nine" @ "0"]; Nsarray *digits = @[@ "A", @ "ten", @ "hundred", @ "thousand", @ "Million", @ "ten", @ "hundred", @ "thousand", @ "Million", @ "ten", @ "hundred", @ "thousand", @ "Mega"]; Nsdictionary *dictionary = [nsdictionary dictionarywithobjects:chinesenumeralsarray ForKeys:arabicNumeralsArray]; if (Arabicnum < && arabicnum > 9) {if (Arabicnum = =) {return @ "ten"; }else{nsstring *substr1 = [Arabicnumstr substringwithrange:nsmakerange (1, 1)]; NSString *a1 = [dictionary objectforkey:substr1]; NSString *chinese1 = [NSString stringwithformat:@ "10%@", A1]; return chinese1; }}else{Nsmutablearray *sums = [Nsmutablearray array]; for (int i = 0; i < arabicnumstr.length; i + +) {nsstring *substr = [Arabicnumstr substringwithrange:nsmakerange (I, 1)]; NSString *a = [dictionary objectforkey:substr]; NSString *b = digits[arabicnumstr.length-i-1]; NSString *sum = [a stringbyappendingstring:b]; if ([a isequaltostring:chinesenumeralsarray[9]]) {if ([b isequaltostring:digits[4]] | | [b isequaltostring:digits[8]]) {sum = b; if ([[[Sums Lastobject] isequaltostring:chinesenumeralsarray[9]) {[Sums removel Astobject]; }}else {sum = chinesenumeralsarray[9]; } if ([[[Sums Lastobject] isequaltostring:sum]) {continue ; }} [sums addobject:sum]; } NSString *sumstr = [sums componentsjoinedbystring:@ ""]; NSString *chinese = [Sumstr substringtoindex:sumstr.length-1]; return Chinese; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"iOS Development series" converts Arabic numerals to Chinese numerals