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 July 2015.
Math.PI
プロパティは、円周と直径の比率、およそ 3.14159 を表します。
試してみましょう
function calculateCircumference(radius) {
return 2 * Math.PI * radius;
}
console.log(Math.PI);
// Expected output: 3.141592653589793
console.log(calculateCircumference(10));
// Expected output: 62.83185307179586
値
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® 2025 Language Specification # sec-math.pi |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PI |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.