可能重复:
JavaScript 等效于 printf/string.format
如何使用 JavaScript 创建 Zerofill 值?
我在变量中有一个数字:
var number = 5;
我需要将该数字输出为 05:
alert(number); // I want the alert to display 05, rather than 5.
我怎样才能做到这一点?
我可以手动检查数字并将 0 作为字符串添加到它,但我希望有一个 JS 函数可以做到这一点?