Reputation: 751
I was trying to save the coordinates
(75.8572998 = 7 digits after decimal point)
to NSUSERDEFAULT
.
But when I fetch it back it shows the value only up to 3 digits after decimal
i.e. 75.857.
I tried to convert the coordinates to string or float before saving it to user defaults.
But no luck.
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
Upvotes: 0
Views: 578
Reputation: 15248
Swift 4.2 playground tested code to save larger numbers,
let cor = 75.8572998232
UserDefaults.standard.set(cor, forKey: "cor")
let v = UserDefaults.standard.double(forKey: "cor")
print("Coordinate value is: \(v)")
Output
Coordinate value is: 75.8572998232
Upvotes: 4