i have this statement
pi = 4*(1-(1/3))
then i print it out.. pi is a double set to 0..
but it keeps printing out 4.0
instead of 2.6666666667 :( help
Printable View
i have this statement
pi = 4*(1-(1/3))
then i print it out.. pi is a double set to 0..
but it keeps printing out 4.0
instead of 2.6666666667 :( help
You're using ints to do double calculations. With integers, 1/3 is 0. 1-0 is 1. 4 * 1 is 4, so you get 4.0.
To see this better, do it in a few steps:
Code :
int step1 = 1/3; System.out.println(step1); int step2 = 1 - step1; System.out.println(step2); int step3 = 4 * step2; System.out.println(step3);
so do i just create a double variable like
double tmp = 0.3;
to use 1/3?
uhh ok nevermind i got it thanks :)