0

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?

4
Contributors
4
Replies
14
Views
2 Years
Discussion Span
Last Post by coder91
1

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);
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.