1. Home
  2. Computing & Technology
  3. PHP / MySQL

The Pi () function and M_PI

By , About.com Guide

The PI () Function: The PI () function is used in many mathematical calculations and is approximately equal to 3.14159265358979323846. By default it will use a precision of 14 decimals, however this can be changed and set as high as 20 in the php.ini file. Here are some examples of it in use:
<?php
echo pi() ;
echo "<br>";
echo pi () * 4;
?>
Using M_PI: M_PI is a constant that will produce the same value as PI (). Our previous example could be rewritten using M_PI like this:
<?php
echo M_PI;
echo "<br>";
echo M_PI * 4;
?>
Other Variations:
M_PI_2 = Half of PI ()
M_PI_4 = One Quarter PI ()
M_1_PI =One divided by PI ()
M_2_PI = Two divided by PI ()
M_SQRTPI = Square root of PI ()
M_2_SQRTPI = Two Divided by the square root of PI ()
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Pi - Using Pi in PHP - PHP 3.141592 Pi

©2009 About.com, a part of The New York Times Company.

All rights reserved.