Search code examples
objective-cdigits

How can I add a zero to the left of a 1 digit integer in Objective C?


How can I add a zero to the left of a 1 digit integer ? Is there any objective C function to perform this? I am needing this so I can have only one NSDateFormat @"ddMMyyyy" thanks

I want to add a zero to the left of an integer which is less than 10, I don't want to use an if statement. Is there any function or way to achieve this?


Solution

  • Use the string format specifier %02d and any single digit integer will be padded with a zero in a string.