views:

393

answers:

4

Ok, so I am pulling an NSString from and NSMutableArray and storing it in an NSString:

entry = [NSString stringWithString:[array objectAtIndex:row]];

This is wrapped inside of a couple different for-loops. I then convert it to a doubleValue and store it in a number but apparently [entry doubleValue] only returns a NaN instead of a number. I threw in an NSLog for 'entry' and '[entry doubleValue]'. EVERY time I run this I get the same results:

entry: 22.414 value: nan

Any ideas? thanks!

+3  A: 

you might check to be sure that you don't have spaces or nonprinting characters in entry

Easiest way to do this:

NSLog(@"%@", [entry dataUsingEncoding:NSUTF8StringEncoding]);
cobbal
+1  A: 

If you're certain there aren't any other characters in the strings, have a look at the NSScanner class. It usually does a better job at reading strings.

Ben S
+2  A: 

Yep, I'd say it's probably some non-printing characters. This works fine for me:

NSString *test = @"22.414";
NSLog(@"doubleValue: %f", [test doubleValue]);
Ian Henry
+1  A: 

It may be, that you have set a system language where the locale says you are using for example comma instead of a dot as decimal seperator. I don't know if this happens with double value, but I had issues with NSNumberFormater.