Prototype - toPaddedString() 方法

此方法将数字转换为用 0 填充的字符串,以便字符串的长度至少等于 length。采用可选的 radix 参数,指定用于转换的基数。

语法

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>单击按钮查看结果。</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_number_processing.html