Pad a number with zeros

I’m writing an autocounter in CRM 2011 because for some reason they haven’t included one!! I asked someone who did a free one in CRM 4 if they were upgrading it to CRM 2011 and he said I could have it for $500.


I read this article


it gives you loads of ways to do it and it would be useful if I was using doubles but I am just using plain old ints.  Here is the nice simple method of padding a number with zeros.


private string padNumber(int counter, int padlength)


string result = “”;

string fmt;


fmt = new String(‘0’, padlength);

result = counter.ToString(fmt);

return result;





One thought on “Pad a number with zeros

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.