1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Passing numbers with leading zeros

Discussion in 'C#' started by reppig, Mar 11, 2010.

  1. reppig

    reppig New Member

    Joined:
    Mar 11, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. Judy Garland

    Judy Garland New Member

    Joined:
    Mar 12, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    You can use the custom format string. Please try this:

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

    then you will get "010".

    Hope it helps:D

    ------------------------------
    Judy Garland
    Free Live Chat Software
     
  3. reppig

    reppig New Member

    Joined:
    Mar 11, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much. I thought it would be something easy to do.
     

Share This Page