Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

pi

Returns the number pi.

Syntax

pi(): float

Return value

floatThe value of pi.

Examples

The area of a circle with radius 2:

<?php
 
echo round(pi() * 2 ** 2, 2);

Output:

12.57

The M_PI constant holds the same value:

<?php
 
var_dump(pi() === M_PI);

Output:

bool(true)

Notes

Expressions usually use the M_PI constant — it is shorter and needs no function call.

See also

  • sqrt — Returns the square root of a number.
  • round — Rounds a number to a given number of digits.

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.