smartsanja
smartsanja

Reputation: 4540

How to create a "0000001" type number format?

I want to generate incremental receipt numbers like this format "00000001". Every time new transaction happen, receipt number should increase by 1.

0000001
0000002
0000003

0000010
0000011

0000100
0000101

So, how could I implement this type of number format. Is there any special number formats in objective C?

Upvotes: 5

Views: 3559

Answers (2)

axe
axe

Reputation: 27

How about just answering the question

  NSString *str=[NSString stringWithFormat:@"%08d", intvalue];

change the 8 to however many leading zeros you want

Upvotes: 0

Peter Sarnowski
Peter Sarnowski

Reputation: 11970

If your numbers are integers and only the output matters, you can do:

NSString * output = [NSString stringWithFormat:@"%07d", integer];

to have the number be formatted with 7 digits, leading zeroes.

Upvotes: 22

Related Questions