← 返回首页
Math.PI - JavaScript | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Math.PI

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

Math.PI は静的データプロパティで、円周と直径の比率、およそ 3.14159 を表します。

In this article

試してみましょう

function calculateCircumference(radius) { return 2 * Math.PI * radius; } console.log(Math.PI); // 予想される結果: 3.141592653589793 console.log(calculateCircumference(10)); // 予想される結果: 62.83185307179586

𝙼𝚊𝚝𝚑.𝙿𝙸=π≈3.14159\mathtt{Math.PI} = \pi \approx 3.14159 Math.PI のプロパティ属性
書込可能不可
列挙可能不可
設定可能不可

解説

PI は Math オブジェクトの静的プロパティなので、 Math オブジェクトを生成してプロパティとして使用するのではなく、常に Math.PI として使用するようにしてください (Math はコンストラクターではありません)。

Math.PI の使用

次の関数は Math.PI を使用して、指定された半径を持つ円の円周を計算します。

js
function calculateCircumference(radius) { return Math.PI * (radius + radius); } calculateCircumference(1); // 6.283185307179586

仕様書

Specification
ECMAScript® 2027 Language Specification
# sec-math.pi

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.

関連情報