I want to keep the zero at the beginning of my NSInteger, but when i NSLog it, the zero is removed.
NSInteger myInteger = 05;
NSLog("%d", myInteger);
log: 5
I get 5 instead of 05. How can i keep the 0 at the beginning of the integer?
NSInteger doesn't do "leading" zeros. You're thinking about a number formatting thing.
If you just want to print out leading zeros via "NSLog", try something like:
NSLog( "%02d", myInteger);
Which instructs NSLog to have two digits and if it doesn't reach two digits, do a leading zero.
Take a look at the printf format specifiers (which NSLog tries to conform to) and you'll see how leading zeros are added there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With