Math.PI

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax

							math.PI

Description

The PI property of the Math object is used to get the constant PI. This is approximately 3.14159.

Example

Listing 6.168 shows how the PI property is used. When the user clicks the Calculate button, the doMath function is called, which calculates the value of PI and returns the result to the text box.

Listing 6.168 Example of the PI Property
 <html> <body> <script language="JavaScript"> <!–– Hide // function returns the value of PI function doMath(){ var result = Math.PI; document.form1.answer.value = result; } // End Hide ––> </script> <form name=form1> The Approximate value of PI is: <input type="text" name="answer" size=20> ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.