开发者

Parsing a double from a string

开发者 https://www.devze.com 2023-02-14 04:01 出处:网络
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 do

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

精彩评论

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