1

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";
  }
Didu
  • 79
  • 2
  • 11

3 Answers3

1
  1. By using padLeft

    eg. "1".PadLeft(8, '0');

Ref. Add zero-padding to a string

Community
  • 1
  • 1
Lifewithsun
  • 968
  • 14
  • 34
1

strValue.ToString("D8");

D8 means format as a decimal with up to 8 leading zeroes

Jas
  • 61
  • 1
  • 6
0

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
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
  • Thanks for the help. worked for me. the major problem was I save this values to a csv file which opens with excel. so even this converted successfully, the result won't show in the format that i wanted. so need to find a solution for that. – Didu Jun 06 '17 at 08:12