ios从没有圆角的字符串加倍

时间:2012-11-08 10:37:17

标签: iphone ios double rounding

下面的代码是我的纬度字符串。我不希望它变得圆润。双拉必须是41.04546。

NSString *latitude= @"41.04546";
double lat= latitude.doubleValue;  //it gives 41.0455
CLLocationCoordinate2D coordinat;
coordinat.latitude= lat;

对于不能舍入的精确坐标。

2 个答案:

答案 0 :(得分:19)

试试这条线..

NSString *latitude= @"41.04546";
double lat= [latitude doubleValue];
NSLog(@"\n\n Value Lat ==>> %f",lat);

答案 1 :(得分:2)

使用NSNumberFormatter

- (NSNumber *)numberFromString:(NSString *)string

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc]init]; 
[numberFormatter setNumberStyle:kCFNumberFormatterDecimalStyle];
NSNumber *number = [numberFormatter numberFromString:@"41.04546"];       
NSLog(@"Number : %@ , Double value : %f",number,[number doubleValue]);   

Output:Number : 41.04546 , Double value : 41.045460

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/Reference/Reference.html