So you have a number and want to add zeros to it? Check out my convenient Objective-C method.
You need:
- http://objective-c-functions.blogspot.com/2013/08/nsinteger-to-nsstring.html
/** Returns a two digits number.
Prepends "0" if the number is between 0 and 9.
@param n Integer to manage.
@return Returns a string representing the two-digits number.
@see threeDigits:
*/
+ (NSString *)twoDigits:(NSInteger)n {
NSString *ret = [LMFunctions stringFromInt:n];
if (n>=0 && n<10) {
ret = [NSString stringWithFormat:@"0%d", n];
}
return ret;
}
Download the ready-for-use source file (.m) of Add zeros to a digit number
No comments:
Post a Comment