サイト内検索

Number メソッド一覧

スポンサー

ホーム > Number > toFixed

toFixed

オブジェクトの値を固定小数点表記(fixed-point notation)の文字列に変換します.

シンタックス

numberObject.toFixed(num)
  • num - 小数点以下の桁数

サンプルコード

以下にtoFixedメソッドを使用したサンプルコードを示します.

<html>
  <head>
    <title>toFixedメソッドのサンプルコード</title>
  </head>
  <body>
    <script type="text/javascript" language="javascript">
      var num = 3.141519;
      document.write(num.toFixed(1) + "<br />");
      document.write(num.toFixed(2) + "<br />");
      document.write(num.toFixed(3) + "<br />");
      document.write(num.toFixed(4) + "<br />");
    </script>
  </body>
</html>

実行例

サンプルコードの実行結果は以下のようになります.

3.1
3.14
3.142
3.1415

スポンサード リンク

inserted by FC2 system