Converting string to int without losing the zero in the beginning

后端 未结 10 553
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:27

    If you are just converting to int to test the value, keep the original data around and use the string value of it when you want the leading zeor. If you require the integer to have zero padding after mathematically working with it you will have to format it with sprintf or the like whenever you output it.

提交回复
热议问题