objective-c – 在目标c中将数字转换为单词

前端之家收集整理的这篇文章主要介绍了objective-c – 在目标c中将数字转换为单词前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要写下这样的数字:
1 GT; YEK

123> yeksad o bist o se

1,123> yek hezar o yeksad o bist o se

3,002,001> se milion o do hezar o yek …

我,在目标c的初学者:)

我用c写它但我想把它转换成obj_c!我怎样才能做到这一点?

像这样的东西:

  1. const char *yekan[10]={"","yek","do","se","chahar","panj","shesh","haft","hasht","noh"};
  2. char ary[9]={'0','0','0'};
  3.  
  4. // get a number from user & converting it to string
  5.  
  6. // user number: 123 > the number in ary:000 000 123)
  7.  
  8. // '3' => 3
  9.  
  10. m=(int) ary[8];
  11. m=m-'0';
  12.  
  13. if (j==3) { printf(" %s ",yekan[m]);} // yekan[3] = se
  14.  
  15. output: se

谢谢.

解决方法

NSNumberFormatter类具有将转换数转换为单词的内置功能
  1. NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
  2. [formatter setNumberStyle: NSNumberFormatterSpellOutStyle];
  3. [formatter setLocale:...]; // Set locale if you want to use something other then the current one
  4. NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 100]];

猜你在找的C&C++相关文章