Passing numbers with leading zeros

reppig's Avatar, Join Date: Mar 2010
Newbie Member
I am new to C# having inherited a program that controls an antenna rotor through an RS-232 port. The command which must be sent to the rotor controller is in the form

"W aaa eee" where W is the command, aaa is a 3 digit the azimuth and eee is a 3 digit elevation for the antenna. So, aaa & eee can be any number between 0 and 360.


My problem is - if I want to move to 10, I need to type in 010 and pass 010 over RS232 port. Right now the program drops the leading zero/zeros.



How do I send a number with the leading zeros?? Any help would be wonderful. Many thanks in advance.
Judy Garland's Avatar, Join Date: Mar 2010
Newbie Member
You can use the custom format string. Please try this:

int a = 10;
a.ToString("000");

then you will get "010".

Hope it helps

------------------------------
Judy Garland
Free Live Chat Software
reppig's Avatar, Join Date: Mar 2010
Newbie Member
Thank you very much. I thought it would be something easy to do.