distanceFromLocation to string is way off [duplicate]
So I am trying to take distanceFromLocation and show it as "8 miles" or "1.5 miles" but I end up with "93129432 miles". See comments inline for where it goes wrong.
double roun开发者_运维问答dDouble = round(returnedDouble);
NSNumber *mylngDoubleNumber = [NSNumber numberWithDouble:roundDouble];
if(latDouble == 0 || lngDouble == 0 || roundDouble == 0){
NSString *str = [NSString stringWithFormat:@"0 mi."];
self.distance.text = str;
}else {
NSString *lngDoubleString = [mylngDoubleNumber stringValue]; <-- ok here '98'
NSString *str = [NSString stringWithFormat:@"%d mi.",lngDoubleString]; <-- bad here '93129432'
self.distance.text = str;
}
it should be [NSString stringWithFormat:@"%@ mi", lngDoubleString];
because you are formatting a string.
精彩评论