我正在尝试保存坐标
(75.8572998 = 7 digits after decimal point)
到 NSUSERDEFAULT
。
但是当我取回它时,它只显示小数点后最多 3 位的值
i.e. 75.857.
在将其保存为用户默认值之前,我尝试将坐标转换为字符串或 float 。
但运气不好。
let locationValue:CLLocationCoordinate2D = manager.location!.coordinate
let latitude : Float = Float(locationValue.latitude)
print("location = \(latitude)")
NSUSERDEFAULT.set(latitude, forKey: "lat")
print(NSUSERDEFAULT.double(forKey: "lat"))
location = (30.9009991)
30.9009990692139
最佳答案
Swift 4.2 playground 测试代码以保存更大的数字,
let cor = 75.8572998232
UserDefaults.standard.set(cor, forKey: "cor")
let v = UserDefaults.standard.double(forKey: "cor")
print("Coordinate value is: \(v)")
输出
Coordinate value is: 75.8572998232
关于swift - 将 float 保存到 NSUSERDEFAULT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53465690/