Reputation: 73
I have UILabel in which i want to show $ also it works fine but problem is that it works on simulator correct but when i test this code on device instead $ it shows Rs (Rupess) any idea how to fix this issue.
NSNumber *number=[[NSNumber alloc]initWithInt:1000];
NSString *No = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyStyle];
NSLog(@"%@", No);
UILabel * text=[NSString stringWithFormat:@"%@",No];
NSLog(@"%@",text);
Upvotes: 0
Views: 503
Reputation: 9002
I doubt you want to set the result of [NSString stringWithFormat:@"%@",No]
to a UILabel
instance.
The other answers seem the most likely, choosing the correct device regional settings and using your existing code to output the value in the local format.
However if anyone is interested in outputting a number with an arbitrary currency format:
NSNumber *number = [NSNumber numberWithInt:1000];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencyCode:@"INR"];
NSString *text = [formatter stringFromNumber:number];
NSLog(@"%@", text);
// Release formatter as required
Though why you'd do this instead of just using the currency symbol and a basic string I'm not sure :p
NSString *text = @"₹1,000.00";
Upvotes: 1
Reputation: 1077
you got this issue because in device setting->general->international->reion format -> is INDIA
just change it to the country of your choice like if you want $ symbol then select USA
Upvotes: 0
Reputation: 4500
There's no issue.
localizedStringFromNumber
and NSNumberFormatterCurrencyStyle
to format number it's giving you the number format as per your region.Upvotes: 1
Reputation: 119021
Because by default the formatter will use the locale specified on the device it is being run on. If you want to force a particular display you need to use setLocale:
and supply the appropriate NSLocale
instance.
Upvotes: 1