If I use the following code:
- (NSString*)formatToCurrency:(float)inFloat {
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setMaximumFractionDigits:2];
[currencyFormatter setLocale:[NSLocale currentLocale]];
NSNumber *x = [NSNumber numberWithFloat:inFloat];
return [NSString stringWithFormat:@" %@", [currencyFormatter stringFromNumber:x]];
}
then pass in 203500 when calling the code, I receive the output: $203,500.02.
I'd love to hear some thoughts on what is happening.
Thanks,
Matt
EDIT: XCode was reporting 203500 when I viewed it with the debugger, but when I converted the float to an NSString, it would also show 203500.018. Meaning the problem was in the float and not in the NSNumberFormatter.