I have an int, for example say 45. I want to get NSString from this int padded with 4 zeroes. So the result would be : @"0045". Similar, if the int is 9, I want to get: @"0009".
I know I can count the number of digits, then subtract it from how many zeroes i want padded, and prepend that number to the string, but is there a more elegant way? Thanks.
Try this:
If it works, then you can get padded number with
Update
If you want to have arbitrary number you’d have to create a format for your format:
Update 2
Please see @Ibmurai’s comment on how to properly pad a number with NSLog.