开发者

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

开发者 https://www.devze.com 2023-03-09 14:30 出处:网络
How can I add a zero to the left of a 1 digit integer ? Is there any objective C function to perform this?

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开发者_StackOverflow社区 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?


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


You can use string formatters to add padding to your integer value as shown here: Help in padding numerical strings

0

精彩评论

暂无评论...
验证码 换一张
取 消