js输入1 , 输出001 方法

function PrefixInteger(num, n) {
          return (Array(n).join(0) + num).slice(-n);
 }
然后在js里引用,
num 为传入的数字
n输出的长度    3    000
 
例如:
number = PrefixInteger(1, 3);
输出的结果为001
 
原文地址:https://www.cnblogs.com/li19950227/p/13163547.html