Monday, September 21, 2009

Pad Integer with Zeros using C#

A quick example for padding an Integer with zeros in C#:

System.Int32 intMyInteger = 87366;
System.String strMyInteger = intMyInteger.ToString().PadLeft(20, '0');

1 comment:

  1. //You can also use D
    //D4 = pad with 4 zero's
    string outputValue = String.Format("{0:D4}",12);

    ReplyDelete

Swidget