PHP pi( ) Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report While solving mathematical problems we often come across questions which requires the value of π. Manually inserting the value of PI (π) can be time-consuming and erroneous. It is also not considered as a good programming practice. To solve this issue a built-in function of PHP pi() comes to aid. The pi() function in PHP is used to return the value of π . Also, M_PI is a named constant PHP which gives identical value to that of returned by pi() function. It is slightly faster than the pi() function. Some other predefined named constants related to π are : M_PI_2 : It describes π/2. Its value is 1.570796. M_PI_4 : It describes π/4. Its value is 0.785398. M_1_PI : It describes 1/π. Its value is 0.318309. M_PI : It describes π. Its value is 3.141592. M_2_PI : It describes 2/π. Its value is 0.636619. M_SQRTPI : It describes sqrt(π). Its value is 1.772453. M_2_SQRTPI : It describes 2/sqrt(π). Its value is 1.128379. Syntax: float pi() Parameters: This function does not accept any parameter. Return Value: It returns a floating point value which is an approximate value of PI. Examples: Input : echo(pi()) Output : 3.1415926535898 Input : echo M_PI Output : 3.1415926535898 Below programs illustrate the pi() function in PHP: When pi() function is used: PHP <?php echo(pi()); ?> Output: 3.1415926535898 When M_PI is used for finding the value of PI: PHP <?php echo M_PI; ?> Output: 3.1415926535898 Important Points To Note: The pi() function can be used to return the value of π. M_PI is a named constant which is slightly faster than the pi() function. pi() function returns the value of pi as float. Reference: https://www.php.net/manual/en/function.pi.php Comment More infoAdvertise with us Next Article Company-wise Practice Problems S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-math PHP-function +1 More Practice Tags : Misc Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like