Parsing a double from a string
I am having trouble parsing a double from a string in an iphone app I am working on. This double value is part of a decimal gps location (either latitude or longitude). Using [开发者_开发技巧string doubleValue] or a number formatter always results in nil being returned.
if([elementName isEqual:@"long"]) {
NSLog(@"\t got lon %@",[currentString doubleValue]);
}
This always results in null being logged.
That's because double is a primitive type, not a pointer. Try %f
instead of %@
.
You can find a full list of format commands in here (scroll down a little). Not sure if there's an "official" documentation anywhere.
edit
Apple's documentation is here, thanks to ericgorr.
精彩评论