Below code is rounding my latitude string. i dont want it to get rounded. double lat must be 41.04546.
NSString *latitude= @"41.04546";
double lat= latitude.doubleValue; //it gives 41.0455
CLLocationCoordinate2D coordinat;
coordinat.latitude= lat;
For precise coordinate that must not be rounded.
The "%f" format string means "a floating point number," but "%. 2f" means "a floating-point number with two digits after the decimal point. When you use this initializer, Swift will automatically round the final digit as needed based on the following number.
you need to include <iomanip> and use the std::setprecision manipulator. To get the level of accuracy you want you will need to use double s rather than float s.
float and double both have varying capacities when it comes to the number of decimal digits they can hold. float can hold up to 7 decimal digits accurately while double can hold up to 15.
Swift enforces you to use Doubles instead of Floats. You should use Float only if you want to sacrifice precision to save memory. Also, if you are working with types that require Float, then you have to use a Float.
try with this line..
NSString *latitude= @"41.04546";
double lat= [latitude doubleValue];
NSLog(@"\n\n Value Lat ==>> %f",lat);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With