Reputation: 79
I need to convert this value to 8 digit format. (example : 1 --> 00000001).any help? here's my code
foreach(DataRow dr in _dsGridCsv.Tables[0].Rows)
{
byte empfrmat =byte.Parse(dr["emp_id"].ToString());
csv += empfrmat;
csv += "\r\n";
}
Upvotes: 1
Views: 2109
Reputation: 71
strValue.ToString("D8");
D8 means format as a decimal with up to 8 leading zeroes
Upvotes: 2
Reputation: 998
By using padLeft
eg. "1".PadLeft(8, '0');
Ref. Add zero-padding to a string
Upvotes: 1
Reputation: 29036
So you want to change the value to 8 digit format, according to the example that you specified, you can try the following code for this:
int value = 1;
String outputStr = value.ToString("00000000");
Console.WriteLine(outputStr) // this will print 00000001
Upvotes: 0