I create an array called testArray. I then save it to user defaults. And retrieve it from user defaults. When I log the original "testArray" and log the retrieved "retrieveArray", the longitude and latitude fields have changed.
For example:
testArray: "longitude": 31.132013199999999
retrievedArray: "longitude": 31.1320132
Why is this? And stranger still - why is the retrieved array logging correctly, but the original array is getting logged with extra decimal places?
Thank you.
let testarray =
Array(
arrayLiteral:
["longitude":31.1320132],
["longitude":31.1320132],
["longitude":31.1320132],
["longitude":31.1320132])
UserDefaults.standard.set(testarray, forKey: "myTestArray")
let retrievedArray = UserDefaults.standard.value(forKey:"myTestArray")
NSLog((testarray as! Array<Dictionary<String,Any>>)[2].description)
NSLog((retrievedArray as! Array<Dictionary<String,Any>>)[2].description)
OUTPUT
app[75897:9783167] ["longitude": 31.132013199999999]
app[75897:9783167] ["longitude": 31.1320132]
UPDATE: Some have said that "duplicate question" is used too aggressively on StackOverflow, and I have noticed that at times. But in this case, yes! This "duplicate question" does seem to speak to the issue. Thank you.