开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜