Duaan
Duaan

Reputation: 609

Substring NSString upto limited number of character after occurrence of specific character?

I have distance in following format.

36.5067714083419

I want two character after occurrence of dot "." So the above String must look like

36.50

Thanks

Upvotes: 1

Views: 121

Answers (1)

Daniel Larsson
Daniel Larsson

Reputation: 6394

Why are you using an NSString? By judging the name and the value of the variable I would suggest using a float. Then you can just do the following:

NSString* formattedNumber = [NSString stringWithFormat:@"%.02f", myFloat];

Upvotes: 1

Related Questions