I have an integer that must remain 8 digits 00000001, it must remain 8 digits after incrementing it. I had it declared as an integer but it wasnt recognising the leading zeros so I have changed it to a string however I need to increment the digit which i cant do when it is a string. Any suggestions?

Recommended Answers

definately keep it as an integer. to add pritaeas suggestion, you can display it as a string by adding the leading zeros..

int num = 1;
Label1.Text = String.Format("{0:00000000}", num);
Jump to Post

All 4 Replies

concatenate probably?

You should keep it as an int, and display with leading zeroes where necessary.

definately keep it as an integer. to add pritaeas suggestion, you can display it as a string by adding the leading zeros..

int num = 1;
Label1.Text = String.Format("{0:00000000}", num);

Thanks everyone, I was able to do it a similar way as suggested excepted i used:

int number = 1;

number.ToString("D8")

Works just the way I need it to.