# formate integer help needed

• ### Question

• hello

I want formate integer values as follow

1 = 0000000001

2= 0000000002

3= 0000000003

......

100= 0000000100

It's Me
Monday, October 31, 2011 8:46 AM

• Try this:

String.Format("{0:00000}", 15);          // "00015"

• Marked as answer by Sunday, November 6, 2011 11:39 AM
Monday, October 31, 2011 8:48 AM
•             int a = 1;
int b = 100;
string a1 = String.Format("{0:0000000000}", a);
string b1 = String.Format("{0:0000000000}", b);

Mitja
• Marked as answer by Sunday, November 6, 2011 11:40 AM
Monday, October 31, 2011 8:52 AM
• But remember, this will be a string, proper integer value cannot have leading zeros. Becuase leading zero is the same and there is no leading zeros.
Mitja
• Marked as answer by Sunday, November 6, 2011 11:40 AM
Monday, October 31, 2011 8:53 AM

### All replies

• Try this:

String.Format("{0:00000}", 15);          // "00015"

• Marked as answer by Sunday, November 6, 2011 11:39 AM
Monday, October 31, 2011 8:48 AM
• You keep it as an integer, but when you display it on the screen you make it into a string like this:

int i = 9;

string s = string.Format("{0:0000}", i);

Monday, October 31, 2011 8:49 AM
•             int a = 1;
int b = 100;
string a1 = String.Format("{0:0000000000}", a);
string b1 = String.Format("{0:0000000000}", b);

Mitja
• Marked as answer by Sunday, November 6, 2011 11:40 AM
Monday, October 31, 2011 8:52 AM
• But remember, this will be a string, proper integer value cannot have leading zeros. Becuase leading zero is the same and there is no leading zeros.
Mitja
• Marked as answer by Sunday, November 6, 2011 11:40 AM
Monday, October 31, 2011 8:53 AM
• Hi It_s Meee,

You can use String.Format() method to format your integer, like BioGeneZ, Thomas and Mitja have told you, but the integer becomes a string after you format it, if you want to operating them, don't forget to convert it to an integer.

Best Regards

Allen Li [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Tuesday, November 1, 2011 6:45 AM