How to convert an Int to a String of a given length with leading zeros to align?

前端 未结 7 1278
醉酒成梦
醉酒成梦 2020-12-12 16:40

How can I convert an Int to a 7-character long String, so that 123 is turned into \"0000123\"?

7条回答
  •  囚心锁ツ
    2020-12-12 17:28

    huynhjl beat me to the right answer, so here's an alternative:

    "0000000" + 123 takeRight 7
    

提交回复
热议问题