java - double being rounded and not precise -
double x = 0; double p = 0.327; //p function return double , change time double w1 = 1/4; //prints 0 (w1 , w2 same p) double w2= 10/4; //prints 2 x=x+p*w1+(1-p)*w2; system.out.println(x); // prints 1.346 , real result 1.76425
i dont know how overcome problem of double rounding down, tried bigdecimal, maybe dont right..
i dont need precise result need result 1.764. in advance.
1 / 4
, 10 / 4
integer divisions. result int, widened double. want double division:
double w1 = 1.0 / 4
or
double w1 = 1 / 4.0
Comments
Post a Comment