Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios double from string without rounded

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.

like image 837
bselvan Avatar asked Nov 08 '12 10:11

bselvan


People also ask

How do I get only 2 decimal places in Swift?

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.

How do I stop my floating from rounding?

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.

What is the difference between Double and Float type of data?

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.

Should I use Double or Float Swift?

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.


1 Answers

try with this line..

NSString *latitude= @"41.04546";
double lat= [latitude doubleValue];
NSLog(@"\n\n Value Lat ==>> %f",lat);
like image 122
Paras Joshi Avatar answered Oct 12 '22 06:10

Paras Joshi