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?
You don’t specify the
NSLocalefor yourNSNumberFormatter, 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 exampleen_USfor example