Mth.PI屬性表示圓周長與其直徑的比值,約為3.14159。
由于PI是Math的靜態(tài)屬性,因此您始終將其用作Math.PI,而不是用作創(chuàng)建的Math對象的屬性。
Math.PI
Math.PI;測試看看?/?
所有瀏覽器完全支持Math.PI屬性:
| 屬性 | ![]() | ![]() | ![]() | ![]() | ![]() |
| Math.PI | 是 | 是 | 是 | 是 | 是 |
| 可寫的: | 沒有 |
|---|---|
| 可枚舉: | 沒有 |
| 可配置的: | 沒有 |
| 返回值: | 表示PI的數(shù)字 |
| JavaScript版本: | ECMAScript 1 |
計算通過半徑的圓的周長:
function getCircumference(radius) {
return (2 * Math.PI * radius);
}
getCircumference(5);測試看看?/?計算通過半徑的圓的面積:
function getArea(radius) {
return (Math.PI * radius * radius);
}
getArea(5);測試看看?/?