我想知道如何在iPhone應用程序中顯示阿拉伯數字而不需要本地化每個數字。如何在iPhone應用程序中顯示阿拉伯數字而不需要本地化每個數字
像例如,我在其值的代碼的整數= 123
我想顯示它作爲123 而不必定位在其自己的每個數位,並迫使該應用使用阿拉伯作爲定位語言,無論用戶選擇的語言
,因爲我有很多的數字遍佈動態變化的應用程序,所以我需要一個通用的聰明的解決方案
我想知道如何在iPhone應用程序中顯示阿拉伯數字而不需要本地化每個數字。如何在iPhone應用程序中顯示阿拉伯數字而不需要本地化每個數字
像例如,我在其值的代碼的整數= 123
我想顯示它作爲123 而不必定位在其自己的每個數位,並迫使該應用使用阿拉伯作爲定位語言,無論用戶選擇的語言
,因爲我有很多的數字遍佈動態變化的應用程序,所以我需要一個通用的聰明的解決方案
NSDecimalNumber *someNumber = [NSDecimalNumber decimalNumberWithString:@"123"];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSLocale *arLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"ar"] autorelease];
[formatter setLocale:arLocale];
NSLog(@"%@", [formatter stringFromNumber:someNumber]); // Prints in Arabic
[formatter setLocale:[NSLocale currentLocale]];
NSLog(@"%@", [formatter stringFromNumber:someNumber]); // Prints in Current Locale
[formatter release];
如果您有浮點數字必須草簽NSNumberFormatter
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
後,加入這行,因此以上代碼的修改將作爲後續
NSString *test = [NSString stringWithFormat:@"%lu", fileSizeEvet];
// NSString *test = [NSString stringWithFormat:@"%f", (double)folderSize/1024/2014];
NSDecimalNumber *someNumber = [NSDecimalNumber decimalNumberWithString:test];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"ar"];
[formatter setLocale:gbLocale];
float myInt = [someNumber floatValue]/1024/1024;
// NSLog(@"%@", [formatter stringFromNumber:[NSNumber numberWithFloat:myInt]]);
// NSLog(@"%@", [formatter stringFromNumber:someNumber]); // Prints in Arabic
NSString *folderSizeInArabic = [formatter stringFromNumber:[NSNumber numberWithFloat:myInt]];
fileSizeLabel.text = [NSString stringWithFormat:@" قهبارهی فایل: %@ مب", folderSizeInArabic];
欲瞭解更多信息請訪問this link
你的意思是「阿拉伯文數字」,而不是「西方阿拉伯數字」。 – Hassan 2012-07-26 13:29:18