js 数字前面自动补零

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

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

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

原文地址:https://www.cnblogs.com/jokerjason/p/9355768.html