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

前端 未结 7 1280
醉酒成梦
醉酒成梦 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:41
    def leftPad(s: String, len: Int, elem: Char): String = {
     elem.toString * (len - s.length()) + s
    }
    
    0 讨论(0)
提交回复
热议问题