IBG
IBG

Reputation: 465

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 something 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.

Upvotes: 0

Views: 166

Answers (2)

BoltClock
BoltClock

Reputation: 723528

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];

Upvotes: 5

scorpiozj
scorpiozj

Reputation: 2687

try this

NSLog(@"%.6d",3);

more info please refer to NSDataformatter.

Upvotes: 1

Related Questions