I am trying to convert an int to a string in objective-C.
I read the other questions on SO about converting ints to strings, and I tried this method in my code:
-(void)setCounter:(int)count
{
counterText.text = [NSString stringWithFormat:@"%d",count];
}
However, if I want to display a number like ’01’ the 0 is taken out of the conversion and only ‘1’ is displayed. Is there a workaround?
There is no such number as
01. If you writeit is compiled equivalently to
In fact, be careful:
07is equivalent to7, but011is equivalent to9!What you can do is ask
stringWithFormat:to give you the zero-padding:should give you
"02"ifcountis 2. To deconstruct it: