Reputation: 484
I'm currently trying to format a float from a JSON feed to a number with NSNumberFormatter using currency style.
My current solution is this:
float test = 100.50;
NSNumber *number = [NSNumber numberWithFloat:test];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencyCode:@"DKK"];
NSString *price = [formatter stringFromNumber:number];
My problem is that the output is 'DKK100.50' when the correct result for the selected currency should be 'DKK100,50' (notice the current result is with a dot as decimal seperator and not a comma as it should).
What am I doing wrong?
Upvotes: 4
Views: 492
Reputation: 4131
You don't specify the NSLocale
for your NSNumberFormatter
, it will use the current "region" in the setting, to set up the currency format (that includes the separator). Your current "region" setting might be a region that use dot as separator, change it to the one that use comma, for example en_US
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
for example
Upvotes: 1