Prototype-number-topaddedstring
提供:Dev Guides
プロトタイプ-toPaddedString()メソッド
このメソッドは、文字列の長さが少なくともlengthと等しくなるように、数値を0で埋められた文字列に変換します。 変換に使用するベースを指定するオプションの基数引数を取ります。
構文
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>