views:

52

answers:

1

Consider this code:

NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.numberStyle = NSNumberFormatterCurrencyStyle;

NSLocale *l = [[NSLocale alloc] initWithLocaleIdentifier:@"it_IT"];
nf.locale = l;
[l release];
nf.decimalSeparator = @",";
nf.currencySymbol = @"US$";
[nf setLenient:YES];
NSString *s = @"US$ 0,05";
double d = [[nf numberFromString:s] doubleValue];
NSLog(@"%.2f",d);`

If I execute this in a normal Cocoa console-based application (10.6 sdk), I get the output "0.05" to the debug console.

However, if I execute this in the iPhone environment (OS 3.1.3), I get "0.00" output to the debug console. Am I doing something wrong with my usage of NSNumberFormatter? Or is this a discrepancy between the two platforms?

A: 
NSString *s = @"US$ 0,05";

What if you remove the space?

Peter Hosey