js 数字前面自动补零

num传入的数字,m需要的字符长度

  function PrefixInteger(num, m) {
      return (Array(m).join(0) + num).slice(-m);
  }

例如:传入8,需要的字符长度为3,调用方法后字符串结果为:008

posted @ 2018-07-23 17:20  JokerJason  阅读(7923)  评论(0编辑  收藏  举报

It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things