Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 要浮动的XML值(到NSString)_Iphone_Xml_Nsstring_Floating Point - Fatal编程技术网

Iphone 要浮动的XML值(到NSString)

Iphone 要浮动的XML值(到NSString),iphone,xml,nsstring,floating-point,Iphone,Xml,Nsstring,Floating Point,我正在使用TBXML解析一个xml文件。 其中一个值是纬度坐标(例如45.503508)。 我需要读取它并将其转换为浮点变量 我正在这么做 TBXMLElement *loc_latitudine = [TBXML childElementNamed:@"latitude" parentElement:loc_location]; //read the xml attribute NSString *string = [NSString stringWithFormat:@"%@", [TBXM

我正在使用TBXML解析一个xml文件。 其中一个值是纬度坐标(例如45.503508)。 我需要读取它并将其转换为浮点变量

我正在这么做

TBXMLElement *loc_latitudine = [TBXML childElementNamed:@"latitude" parentElement:loc_location]; //read the xml attribute
NSString *string = [NSString stringWithFormat:@"%@", [TBXML textForElement:loc_latitudine]];
float myfloat = [string floatValue];
NSLog(@"%f", myfloat);
有什么问题吗? 如果我的xml值是45.503508,“myfloat”的值是45.000000! 每一次


怎么了?

问题似乎是XML元素返回的字符串中有一个逗号(而不是句点)


因此,您应该能够使用
stringByReplacingOccurrencesOfString:withString:
方法将其替换为一个句点,然后使用NSString
doubleValue
方法提取所需的图形。

NSLog(@“string:%@”,string);是“45503508”。使用
[string doubleValue]
(与floatValue相反)有什么区别吗?没有人:(我试图将字符串中的“.”替换为“.”,但什么都没有!啊-没有注意到逗号。您如何尝试替换它?(可能是NSString
stringByReplacingOccurrencesOfString:withString:
方法?)是的,是的,我试过了…但是没有改变!!