How to prevent the rounding off when getting doubleValue from string?(从字符串中获取 doubleValue 时如何防止舍入?)
问题描述
我从服务器以字符串格式的 JSON 获取纬度和经度,然后我通过使用默认的 doubleValue 函数将纬度和经度的值转换为双精度值来使用此纬度和经度,但使用此值四舍五入.那么,从字符串中获取 doubleValue 时如何防止舍入?这是我的代码
I am getting latitude and longitude from server in JSON which is in string format then i am using this latitude and longitude by converting the values of latitude and longitude in double value by using default doubleValue function but by using this value is rounded off. So, How can i prevent the rounding off when getting doubleValue from string? Here is my code
CLLocationCoordinate2D defaultLoc;
defaultLoc.latitude = [[self.obj valueForKey:@"latitude"] doubleValue];
defaultLoc.longitude = [[self.obj valueForKey:@"longitude"] doubleValue];
NSLog(@"latitude : %f longitude : %f",defaultLoc.latitude,defaultLoc.longitude);
推荐答案
格式说明符 %f
默认情况下将双精度值四舍五入到小数点后六位.尝试将格式指定为 %.10f
或您需要的任何小数位数.
The format specifier %f
rounds the double values to six decimals by default. Try specifing the format as %.10f
or whatever number of decimals you need.
这篇关于从字符串中获取 doubleValue 时如何防止舍入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从字符串中获取 doubleValue 时如何防止舍入?


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01