Transform NSInteger to NSString as a 5-digit number
-
14-07-2021 - |
Question
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.
Solution
Use the %05d
format specifier in order to pad with zeroes:
NSString *myStr = [NSString stringWithFormat:@"%05d", myInt];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow