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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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: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.