Appending Zeros. RRS feed

  • Question

  • User-1042970710 posted

    I have a special requirement where I have to append my  primary key in this pattern:

    For Example:

    If my key is 1  then the result will be 000000001  (Eight Zeros)

    If my key is 5  then the result will be 000000005  (Eight Zeros)

    If my key is 10  then the result will be 000000010  (Server Zeros)

    If my key is 100  then the result will be 000000100  (Six Zeros)

    I used the following code which works fine in DotNetFiddle.

    var s=String.Format("{0:000000000}", 1);

    giving me : 000000001  Which correct but when I use the same in my Code It didn't change the value at all can anyone help me with this?

     var jobPostionCode = String.Format("{0:000000000}", JobInfo.JobPositionCode.ToString());

    my value didn't got changed!!

    Please note that JobPostionCode contains a integer value which I convert into String....  

    Monday, April 13, 2020 12:38 PM


  • User-18289217 posted

    Remove the ToString() and try again

    In addition you may want to try the following:

    var s = JobInfo.JobPositionCode.ToString("00000000");


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 13, 2020 1:48 PM