I need to write an algorithm to find pi, using the formula
pi/4 = 1 - 1/3 + 1/5 - 1/7 +- ...
- They also want us to make it stop after it has calculated six digits.
- And does anyone know how to make it round off?
My code currently is:
public class Pi
{
public static void main(String[] args)
{
double sum = 1;
int sign = -1;
double value = 3;
while (value < 10_000_000_000)
{
sum = sum + sign / value;
value = value + 2;
sign = sign * -1;
}
System.out.println("The value of pi is: " + (4 * sum));
}
}
Right now it runs like this
The value of pi is: 3.1415926335902506
I need it to calculate and output 3.141593
.