Formatting a float number inside a Mutable string

93 views Asked by At

I have a couple of floats and they all are stored in a mutable string. But while displaying them it's showing 2011.00000 inspite of 2011 so i want it to format it. Any suggestions.

Thanks

3

There are 3 answers

0
Nyx0uf On BEST ANSWER
NSString* str = [NSString stringWithFormat:@"%.f", float_number];
0
HeikoG On

Could you just put them into floats and then use a stringWithFormat(@"%f4.0", ?

0
Max On

Use

NSString* sa = [NSString stringWithFormat: @"%0.0f", 22323.4342];