static void Main()
// Get PI from methods shown here
double d = PI();
// Get PI from the .NET Math class constant
double d2 = Math.PI;
static double PI()
// Returns PI
return 2 * F(1);
static double F(int i)
// Receives the call number
if (i > 60)
// Stop after 60 calls
// Return the running total with the new fraction added
return 1 + (i / (1 + (2.0 * i))) * F(i + 1);
Newton. Isaac Newton spent a long time calculating pi to 15 decimal places. You can see that the equation defines half of pi as the sum of a fraction, expanded from 0 to infinity.
Info The result of the formula becomes increasingly accurate the longer you calculate it.
Summary. We used the Math.PI constant. We then saw a way to calculate the value of pi. We learned about double precision and the string format patterns for decimal places.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Nov 17, 2021 (edit link).