Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display arabic numbers inside iPhone apps without localizing each digit

I want to know how to display arabic numbers inside iPhone apps without localizing each digit.

like for example, I have an integer in the code whose value = 123

I want to display it as ١٢٣ without having to localize each digit on its own and force the app to use arabic as the localization language regardless of the user's chosen language

because I have many numbers all over the application that change dynamically, so I need a generic smart solution

like image 706
Evronia Avatar asked Jul 26 '12 13:07

Evronia


1 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];
like image 193
Aravindhan Avatar answered Sep 19 '22 00:09

Aravindhan