Reputation: 6203
float distance = 2347293874923;
NSNumber * dist = [NSNumber numberWithFloat:distance];
How to get only first 3 digits of dist in a NSString.
Upvotes: 0
Views: 442
Reputation: 172458
Try this:
float distance = 2347293874923;
NSString * n = [NSString stringWithFormat:@"%f", distance];
NSString * s = [n substringToIndex:3];
NSLog(@"%@", s);
Upvotes: 3