Converting string to int without losing the zero in the beginning

后端 未结 10 550
Happy的楠姐
Happy的楠姐 2021-01-02 03:49

I tried int.parse, and convert class to convert a string to int.

While I\'m converting. I\'m losing the 0 in the beginning which i don\'t want.

10条回答
  •  [愿得一人]
    2021-01-02 04:24

    myNumber.ToString("D5");
    

    //D represents 'Decimal', and 5 is the specified amount of digits you want the number to be always. This will pad your value with zeroes until it reaches 5 digits.

提交回复
热议问题