ios - How to convert numbers into text? -


i have been learning objective-c kochan book , can't figure out how exercise program. odd numbered exercises listed online , 1 even. exercise convert numbers words. so, if "932" entered, program should return: "nine 3 two"

i used do, while loop words came out backwards, in "two 3 nine". can suggest technique works this?

int number, digit;   nslog(@"type in integer."); scanf("%i", &number);     {      digit = number % 10;       if (digit == 0)          nslog(@"zero");      if (digit == 1)          nslog(@"one");      if (digit == 2)          nslog(@"two");      if (digit == 3)          nslog(@"three");      if (digit == 4)          nslog(@"four");      if (digit == 5)          nslog(@"five");      if (digit == 6)          nslog(@"six");      if (digit == 7)          nslog(@"seven");      if (digit == 8)          nslog(@"eight");      if (digit == 9)          nslog(@"nine");       number /= 10;  } while (number != 0); 

this isn't exactly want, consideration:

nsnumberformatter *f = [[nsnumberformatter alloc] init]; [f setnumberstyle:nsnumberformatterspelloutstyle];  nsstring *s = [f stringfromnumber:[nsnumber numberwithint:932]]; nslog(@"%@", s); [f release]; 

this log:

nine hundred , thirty-two 

again, it's not "nine 3 two" want, it's nice , short. :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -