Javascript-number-tostring
提供:Dev Guides
JavaScript番号-toString()
説明
このメソッドは、指定されたオブジェクトを表す文字列を返します。 * toString()*メソッドは最初の引数を解析し、指定された基数(ベース)で文字列表現を返そうとします。
構文
その構文は次のとおりです-
number.toString( [radix] )
パラメータの詳細
*radix* -数値の表現に使用するベースを指定する2〜36の整数。
戻り値
指定されたNumberオブジェクトを表す文字列を返します。
例
次の例を試してください。
<html>
<head>
<title>JavaScript toString() Method </title>
</head>
<body>
<script type = "text/javascript">
num = new Number(15);
document.write("num.toString() is " + num.toString());
document.write("<br/>");
document.write("num.toString(2) is " + num.toString(2));
document.write("<br/>");
document.write("num.toString(4) is " + num.toString(4));
document.write("<br/>");
</script>
</body>
</html>
出力
num.toString() is 15
num.toString(2) is 1111
num.toString(4) is 33