How to display Arabic numbers inside iPhone applications without localizing each digit

I want to know how to display Arabic numbers in iPhone applications without localizing each digit.

like for example i have an integer in code whose value = 123

I want to show it as 123 without having to localize each digit on my own and force the application to use Arabic as a localization language, regardless of the language chosen by the user.

because I have many numbers throughout the application that change dynamically, so I need a general smart solution

+7
source share
2 answers
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]; 
+22
source

If you have floating point numbers, you should add this line after initializing NSNumberFormatter [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; therefore a modification of the above code will follow

 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]; 

For more information, visit this link.

+1
source

All Articles