Google News
logo
PHP Program to Find the value of PI
In PHP, you can get the value of PI using the `pi()` function. Here's an example :
Program :
<?php
$pi = pi();
echo "The value of pi is: $pi";
?>
Output :
The value of pi is: 3.1415926535898
The `pi()` function returns the value of pi to 14 decimal places by default. If you need more precision, you can use the `M_PI` constant, which is a built-in constant in PHP that has a higher precision :
Program :
<?php
$pi = M_PI;
echo "The value of pi is: $pi";
?>
Output :
The value of pi is: 3.1415926535898
Note that `M_PI` is a constant and not a function, so you don't need to call it with parentheses.