サイト内検索

Math メソッド一覧

スポンサー

ホーム > Math > abs

abs

絶対値を返します.

シンタックス

Math.abs(x)
  • x - 数値

解説

absメソッドはxの絶対値を返します.

サンプルコード

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

<html>
  <head>
    <title>absメソッドのサンプルコード</title>
  </head>
  <body>
    <script type="text/javascript" language="javascript">
      document.write(Math.abs(10) + "<br />");
      document.write(Math.abs(-10) + "<br />");
      document.write(Math.abs(0) + "<br />");
      document.write(Math.abs(-0) + "<br />");
      document.write(Math.abs(NaN) + "<br />");
      document.write(Math.abs(Infinity) + "<br />");
      document.write(Math.abs(-Infinity) + "<br />");
    </script>
  </body>
</html>

実行例

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

10
10
0
0
NaN
Infinity
Infinity

スポンサード リンク

inserted by FC2 system