原型 - 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
廣告
© . All rights reserved.