I have a number that I am trying to append to an array. The number is a coordinate -37.77745068746633 however in my Swift project if I println the array after the append call the value that should be -37.77745068746633 is -37.77745069
I am receiving the number through Google snap to roads API and I can see the original as the full number but changes after I call
self.latitude = locations["latitude"] as! Double
Swift just doesn't seem to store the entire value. Is there rounding on by default?
If you keep the number as Double all the time, Swift won't round it, it is most likely the print statement that truncates it to a reasonable precision.
By the way, try to check the distance between the original and the truncated coordinates:
let lat1: Double = -37.77745068746633 let lat2: Double = -37.77745069 let lon: Double = 150 let loc1 = CLLocation(latitude: lat1, longitude: lon) let loc2 = CLLocation(latitude: lat2, longitude: lon) print(loc1.distanceFromLocation(loc2)) // prints 0.000281218294500339
If I am not making any mistake, the difference is just 0.3 millimeters.