原型 - toPaddedString() 方法
此方法将数字转换为以 0 填充的字符串,使得该字符串的长度至少等于 length。获取一个可选的基数参数,用于指定用于转换的基数。
语法
number.toPaddedString(length[, radix]);
返回值
返回一个字符串。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
alert("(13).toPaddedString(4) : " + (13).toPaddedString(4) );
alert("(13).toPaddedString(2) : " + (13).toPaddedString(2) );
alert("(13).toPaddedString(1) : " + (13).toPaddedString(1) );
alert("(13).toPaddedString(4, 2): " + (13).toPaddedString(4, 2));
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_number_processing.htm
广告