Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 246
Stefano Romani Avatar asked Jan 14 '23 17:01

Stefano Romani


1 Answers

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

like image 158
Martin R Avatar answered Jan 21 '23 22:01

Martin R