2010-07-31 61 views
5

我需要寫號碼,如: 1> YEK轉換數目即,在目標C

123> yeksadöBISTö本身

1123> YEK hezaröyeksadöBISTö本身

3002001> SE暢想o不要hezarØYEK ...

我,在客觀C :)

米初學者我把它寫在C,但我想轉換它,進入obj_c!我怎樣才能做到這一點?

財產以後這樣的:

const char *yekan[10]={"","yek","do","se","chahar","panj","shesh","haft","hasht","noh"}; 
char ary[9]={'0','0','0','0','0','0','0','0','0'}; 

// get a number from user & converting it to string 

// user number: 123 > the number in ary:000 000 123) 

// '3' => 3 

m=(int) ary[8]; 
m=m-'0'; 

if (j==3) { printf(" %s ",yekan[m]);} // yekan[3] = se 

output: se 

感謝。

回答

21

NSNumberFormatter類具有內置的功能轉換號碼的話:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
[formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 
[formatter setLocale:...]; // Set locale if you want to use something other then the current one 
NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 100]]; 
+0

感謝您的回答:)的斯威夫特版本,但我如何設置區域設置爲波斯env ...? – aden 2010-07-31 10:56:12

+0

Wo0oW我可以設置persianlocal :) NSLocale * persianLocale = [[NSLocale alloc] initWithLocaleIdentifier:@「fa_IR」]; 再次感謝:* – aden 2010-07-31 11:27:32

+0

非常感謝。:) – 2012-08-21 14:22:32

0

@Vladimir答案(以防萬一)

let formatter = NSNumberFormatter() 
formatter.numberStyle = .SpellOutStyle 
formatter.locale = NSLocale(localeIdentifier: "en_US") 
let string = formatter.stringFromNumber(55015515)