How to make a "0000001" NSString
Another noob question from me. I'm trying to create an application that counts, and I'd like to display the number value as som开发者_Go百科ething like "000001". So when it counts up it'll display as "000002".
I'm using something like this right now, but it's not working:
counter.text = [NSString stringWithFormat:@"%000f", count];
The counter.text is a UILabel.
Thanks for the answer.
If you're storing the number as an integer, use the %0xd
format (where x
is the number of digits) like so:
counter.text = [NSString stringWithFormat:@"%06d", count];
try this
NSLog(@"%.6d",3);
more info please refer to NSDataformatter.
精彩评论