Math.PI

Math.PI 静态数据属性表示圆的周长与其直径的比率,大约为 3.14159。

¥The Math.PI static data property represents the ratio of the circumference of a circle to its diameter, approximately 3.14159.

Try it

¥Value

𝙼𝚊𝚝𝚑.𝙿𝙸 = π 3.14159 \mathtt{Math.PI} = \pi \approx 3.14159

Property attributes of Math.PI
Writable no
Enumerable no
Configurable no

描述

¥Description

因为 PIMath 的静态属性,所以你始终将其用作 Math.PI,而不是用作你创建的 Math 对象的属性(Math 不是构造函数)。

¥Because PI is a static property of Math, you always use it as Math.PI, rather than as a property of a Math object you created (Math is not a constructor).

示例

¥Examples

使用 Math.PI

¥Using Math.PI

以下函数使用 Math.PI 计算具有传递半径的圆的周长。

¥The following function uses Math.PI to calculate the circumference of a circle with a passed radius.

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

calculateCircumference(1); // 6.283185307179586

规范

Specification
ECMAScript Language Specification
# sec-math.pi

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also