1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

输出对齐(填充空格)

This commit is contained in:
2022-10-29 17:40:25 +08:00
parent c02dcdf814
commit d332563905
3 changed files with 20 additions and 3 deletions

13
utils/stringUtils.js Normal file
View File

@@ -0,0 +1,13 @@
// 数字转成字符串,同时在前面填充
function fill(num, length, fillers = " ", atLast = false) {
var result = `${num}`;
if (result.length < length) {
let fillString = new Array(length - result.length + 1).join(fillers)
result = atLast ? `${result}${fillString}` : `${fillString}${result}`;
}
return result;
}
module.exports = {
fill,
}