How to create number format "0000001"?

I want to generate receipt serial numbers like this format "00000001". Each time a new transaction occurs, the receipt number should increase by 1.

0000001 0000002 0000003 0000010 0000011 0000100 0000101 

So how could I implement this type of number format. Are there special number formats in the C object?

+4
source share
2 answers

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

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

so that the number is formatted with 7 digits leading zeros.

+20
source

How to simply answer a question

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

change the value 8 to any number of zeros you need

0
source

Source: https://habr.com/ru/post/1391189/


All Articles