Mth.PI属性表示圆周长与其直径的比值,约为3.14159。
由于PI是Math的静态属性,因此您始终将其用作Math.PI,而不是用作创建的Math对象的属性。
Math.PI
Math.PI;测试看看‹/›
所有浏览器完全支持Math.PI属性:
| 属性 | ![]() | ![]() | ![]() | ![]() | ![]() |
| Math.PI | 是 | 是 | 是 | 是 | 是 |
| 可写的: | 没有 |
|---|---|
| 可枚举: | 没有 |
| 可配置的: | 没有 |
| 返回值: | 表示PI的数字 |
| JavaScript版本: | ECMAScript 1 |
计算通过半径的圆的周长:
function getCircumference(radius) {
return (2 * Math.PI * radius);
}
getCircumference(5);测试看看‹/›计算通过半径的圆的面积:
function getArea(radius) {
return (Math.PI * radius * radius);
}
getArea(5);测试看看‹/›