JS数字指定长度不足前补零的实现

//实现函数
function
fn3(num, length) { return (Array(length).join('0') + num).slice(-length); }

调用:

console.time('3');  
fn3();  
console.timeEnd('time3'); //chrome返回值:time3: 0ms  

 

转载:http://wsj123.iteye.com/blog/2412696

posted @ 2018-08-09 09:45  平民的麦田  阅读(2732)  评论(0编辑  收藏  举报