哪个dataType将返回值(37.961498)?双重无效

时间:2013-10-29 10:58:09

标签: ios iphone objective-c mkmapview type-conversion

哪个dataType会返回值(37.961498)?

我在MapView工作。其中,目前我正在设置注释,因此我必须设置CLLocationCoordinate2DMake,并从googleAPI解析一些lat和lng(例如:lat =“37.9615000”和lng =“60.5566000”)。我有字符串中的值,因此我将sting转换为double然后分配但它没有帮助。请有人帮助我。

   double int1=[num1s floatValue];
    double int2=[num2s floatValue];
   NSLog(@" %f %f ",int1,int2);
    annotation.coordinate=CLLocationCoordinate2DMake(int1, int2);

实际值为:37.9615000,60.5566000 我在NSLog中获得的值:37.961498,60.556599

提前致谢。

更多解释和我需要确切值的原因:

我需要为它的lat和lan设置注释(lat =“53.5609740”;         lng =“134.7728099”)

但是,当从字符串再次转换时,值会更改

enter image description here

3 个答案:

答案 0 :(得分:2)

string转换为double时,您应该使用doubleValue代替floatValue

double int1=[num1s doubleValue];
double int2=[num2s doubleValue];
NSLog(@" %f %f ",int1,int2);
annotation.coordinate=CLLocationCoordinate2DMake(int1, int2);

也不重要,但我不建议将你的双打命名为int1和int2,这可能会让你在某些时候感到困惑

答案 1 :(得分:2)

annotation.coordinate=CLLocationCoordinate2DMake([nums doubleValue], [int2 doubleValue]);

试试这个

答案 2 :(得分:1)

double int1=[num1s floatValue];
double int2=[num2s floatValue];
NSLog(@" %0.7f %0.7f ",int1,int2);
annotation.coordinate=CLLocationCoordinate2DMake(int1, int2);

阅读String Format Specifiers了解详情。