Which dataType will return the value (37.961498) as it is ? Double didn't work

試著忘記壹切 提交于 2020-01-11 08:03:52

问题


Which dataType will return the value (37.961498) as it is?

I am working in MapView. Where, at present I am setting annotation and hence I have to set CLLocationCoordinate2DMake with some lat and lng parsed from googleAPI (Eg:lat = "37.9615000" and lng = "60.5566000") . I have the values in string, hence I converted the sting to double and then assigned But it didn't help. Please some one help me.

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

actual values are: 37.9615000,60.5566000 Values I get in NSLog: 37.961498, 60.556599

Thanks in advance.

More explanation and reason why I need exact value:

I need to set annotation for china With its lat and lan ( lat = "53.5609740"; lng = "134.7728099")

But while converting again from string the value changes


回答1:


When converting a string to a double you should be using doubleValue instead of floatValue

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

also not critical but I wouldn't recommend naming your doubles as int1 and int2 that is likely to cause you confusion at some point




回答2:


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

Try this




回答3:


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

Read String Format Specifiers for more info.



来源:https://stackoverflow.com/questions/19656315/which-datatype-will-return-the-value-37-961498-as-it-is-double-didnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!