Skip to content

Instantly share code, notes, and snippets.

@cxa
Created May 28, 2011 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cxa/996837 to your computer and use it in GitHub Desktop.
Save cxa/996837 to your computer and use it in GitHub Desktop.
Convert Arabic number to Chinese
#define CHAR_MAX 32
NSString* toChineseNumer(NSUInteger num){
static NSString *cnums = @"〇一二三四五六七八九";
unichar ch[32];
int i = 0;
do ch[i++] = [cnums characterAtIndex:num%10];
while ((num /= 10) > 0);
unichar *reverse = calloc(sizeof(unichar), i);
for (int j=0; j<i; j++) reverse[j] = ch[i-j-1];
NSString *ret = [[NSString alloc] initWithCharacters:reverse length:i];
free(reverse);
return [ret autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment