Math.PI
The constant π — the ratio of a circle's circumference to its diameter.
Available since: ES1
Syntax
Math.PIReturn value
numberThe number π, about 3.14159.
Examples
The value of the constant:
console.log(Math.PI);Output:
3.141592653589793The area of a circle with radius 2:
const radius = 2;
console.log((Math.PI * radius ** 2).toFixed(2));Output:
12.57Notes
Math has other constants too: Math.E (the number e), Math.SQRT2 (the square root of two). They cannot be changed.
See also
- Math.pow — Raises a number to a power.
- Number.prototype.toFixed — Formats a number with a given number of decimal places.
In the tutorial
- Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.