How to change 1 to 00001?

后端 未结 9 930
予麋鹿
予麋鹿 2021-01-03 23:59

I want to have numbers with a fixed digit count.

example: 00001, 00198, 48484

I can do like this:

    string value;
    if (number < 10)
          


        
9条回答
  •  既然无缘
    2021-01-04 00:24

    If you wish to return 5 digits numbers, you should use the PadLeft() function;

    int Value = 101;
    char pad = '0';
    String sValue = Value.ToString();
    
    sValue  = sValue.s.PadLeft(5, char)
    

    In this case, you don't have to test whether to add 1, 2 or 3 zeros, it'll automatically add the number of zeros needed to make it 5 digits number.

提交回复
热议问题