Pi Calculator

This web page allows you to calculate Pi using Wallis' Formula and explains how it works.

JavaScript is Disabled

This calculator uses JavaScript to calculate pi. You will need to enable JavaScript before you can use this to play with Wallis' Formula.

Calculate Pi

You can use this simple JavaScript program to calculate pi. The higher the number of iterations to run the more accurate the result will be but the longer it will take for your computer to calculate pi.

Note

Please note that due to the way in which JavaScript does simple math there may be errors in the results.

:

You calculated pi as:

The real value of pi is: 3.141592654...

How does this work?

This little JavaScript uses Wallis' Formula to calculate pi. While probably not the most efficient method it is very easy to implement and understand what is going on.

Wallis' Formula looks like so (4th term shown):

pi / 2 = 2 x 2 x 4 x 4 ... / 1 x 3 x 3 x 5 ...

For 4 terms we get an approximation of 2.8444... (check it above), which is obviously not very accurate, but as we increase the number of iterations we increase the accuracy. For the 60th iteration we get 3.1159... and for the 1,000,000th iteration we get 3.14159... by now the result it accurate enough to do some basic calculations.