2013-10-29 42 views
-1

哪个dataType将返回值(37.961498),因为它是?哪个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

在此先感谢。

更多的解释和理由,为什么我需要确切值:

我需要为中国设置注释凭借其经纬度和LAN(LAT = “53.5609740”; LNG = “134.7728099”)

不过,虽然从字符串转换再次值更改

enter image description here

+6

[每台计算机科学家应该知道浮点运算什么(http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) –

+0

NSString ....... –

+0

顺便问一句,你的问题是什么?为什么你需要确切的结果? –

回答

2

当转换stringdouble,你应该使用doubleValue代替floatValue

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

也并不重要,但我不建议在命名兼作INT1和INT2很可能在某些时候

+0

和NSLog是:5.356097e + 01 1.347728e + 02 :(dint帮助我需要得到53.5609740 134.7728099。 –

+0

@SiddarthHailstorm - 你可能想要改变你的格式来显示所有的数字 - 'NSLog(@“%20.16f%20.16f”,int1,int2);' –

+0

它的现在:53.5609740000000016 134.7728098999999986我需要53.5609740 134.7728099因为一分钟的值会改变注释。还有另外一个问题,对于你来说,对于NSLOg它没问题!如何改变“annotation.coordinate = CLLocationCoordinate2DMake(int1,int2);”??? –

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

阅读String Format Specifiers更多的信息给你造成混乱。

+0

你的代码返回:53.5609741210937500 134.7728118896484375我需要的仅仅是53.5609740 134.7728099。谢谢 –

+1

它应该工作。打印数字时,请再次检查您正在使用的格式。 –

+0

对不起,哥们!它现在完成了!它的印刷准确,但如何实现这一点坐标? annotation.coordinate = CLLocationCoordinate2DMake(int1,int2); ?我将如何在代码中添加这些%0.7?你能告诉我语法吗? –

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

试试这个

+0

no it dint help。check server –

相关问题