Format variable as 4 digits with leading zeroes

后端 未结 4 2095
太阳男子
太阳男子 2020-12-17 10:15

A store number could be 1-4 digits.

Store #26 would be 0026 in respect to how devices are named, but I\'d like to give the techs the ease of being able to type 26 to

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 10:48

    Foreach versions of padleft and tostring. The 0 in the first one has to be quoted:

    '4' | % padleft 4 '0'
    0004
    
    4 | % tostring 0000
    0004
    

    Working with a range:

    1..10 | % tostring 0000
    
    0001
    0002
    0003
    0004
    0005
    0006
    0007
    0008
    0009
    0010
    

    With a prefix:

    1..10 | % tostring COMP0000
    
    COMP0001
    COMP0002
    COMP0003
    COMP0004
    COMP0005
    COMP0006
    COMP0007
    COMP0008
    COMP0009
    COMP0010
    

提交回复
热议问题