Zubair
Zubair

Reputation: 6203

Get first 3 digits of NSNumber

float distance = 2347293874923;
NSNumber * dist = [NSNumber numberWithFloat:distance];

How to get only first 3 digits of dist in a NSString.

Upvotes: 0

Views: 442

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

Try this:

float distance = 2347293874923;
NSString * n = [NSString stringWithFormat:@"%f", distance];
NSString * s = [n substringToIndex:3];

NSLog(@"%@", s);

Upvotes: 3

Related Questions