Pages

Thursday, November 4, 2010

String.format in c sharp, padding with zeros e.g 1 to 001

If you want to pad zero's in front of a number in c# .Net
i.e for example if the given number is 24 and you need to add zero's in front of if
then you should do the following.


e.g Assuming that it is a number, not a string.
Int a=24;// To 0024 


string newStr = String.Format("{0:0000}", 24]);
Output of newStr will be 0024

No comments: