C# - increment number and keep zeros in front

前端 未结 5 655
再見小時候
再見小時候 2021-02-07 10:17

I need to make a 40 digit counter variable. It should begin as 0000000000000000000000000000000000000001
and increment to
000000000000000000000000000

5条回答
  •  面向向阳花
    2021-02-07 10:59

    I had to do something similar the other day, but I only needed two zeros. I ended up with

    string str = String.Format("{0:00}", myInt);
    

    Not sure if it's fool proof but try

    String.Format("{0:0000000000000000000000000000000000000000}", myInt)
    

提交回复
热议问题