Stefano Romani
Stefano Romani

Reputation: 47

Int number 0000 cocos2d

I have a starting number to work from which is 0000 and increment it by one, i have that done, but the result is 1,2,3 instead of 0001,0002,0003 etc. How can I achieve this?

I use this string:

stringa = [NSString stringWithFormat:@"Score: %d",score];

Thank you.

Upvotes: 4

Views: 104

Answers (1)

Martin R
Martin R

Reputation: 539685

stringa = [NSString stringWithFormat:@"Score: %04d",score];

should do what you want.

"4" is the (minimum) field width, and the "0" is for padding with zeroes instead of spaces. stringWithFormat understands (almost) all the "printf" formats (which are described in detail here: http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html ).

Upvotes: 9

Related Questions