swiftstringdoublecllocationcllocationcoordinate2d

Can't convert and use string value in Double - Swift


I have a easy problem but I can't fix it. In my program There are lines where I have a for loop with custom array. This array has got 3 value each of them string(array created by the JSON object from web). Whenever I tried the reach these string variables in double form I can't as pictures show.

This is the for loop I used in app

And this is the debug report

As you can see in the pictures my aim is get he latitude and longitude values turn into double and use in CLLocationCoordinate2D init. but the conversion of string value is for latitude = 35.32041000000002 how can I convert it into presicion 6 digit. Thanks all. Have a nice day.


Solution

  • Read this to understand floating point numbers. In summary: Not all numbers can be exactly represented in the 64-bits of a Double. So you'll end up with something that extremely close, but with extra digit(s), or for example with a long tail of 9999999999.

    The conversion succeeded. The value that the extra digit (0.000000000000002) won't hurt as they are rather insignificant.