1

I have an int and I transform it to a NSString like this:

NSString *myStr = [NSString stringWithFormat:@"%d",myInt];

myInt is ranged from 0 to 99999. What I want is to get myStr as a 5-digit number.

for example : 00072 or 09856 or 00002

Thank you.

tchike
  • 154
  • 4
  • 21

1 Answers1

6

Use the %05d format specifier in order to pad with zeroes:

NSString *myStr = [NSString stringWithFormat:@"%05d", myInt];

Wikipedia's explanation.