在我的应用程序中,我在服务器中获取经度,纬度和存储值。 当我直接打印值时,我可以得到符号(+或 - )。将值存储在浮点数或NSString符号后丢失。任何帮助将不胜感激。谢谢提前
currentLocation = newLocation;
if (currentLocation != nil) {
longtiude = [NSString stringWithFormat:@"%f", currentLocation.coordinate.longitude];
latitude= [NSString stringWithFormat:@"%f", currentLocation.coordinate.latitude];
}
NSLog(@"New Lati%@, Long%@", latitude, longtiude);
答案 0 :(得分:1)
要始终在转换的数字前加上一个符号(+
或-
),请将+
添加到格式说明符中:
NSString *s1 = [NSString stringWithFormat:@"%f %f", 1.3, -1.3];
// Output: 1.300000 -1.300000
NSString *s2 = [NSString stringWithFormat:@"%+f %+f", 1.3, -1.3];
// Output: +1.300000 -1.300000