Sorry for this basic question, but I just can not understand why the following lines of code returns the result "k=0.0"
double k; k=2/(6+1); print("k="+k);
I would expect k=0.28571428571428571428571428571429 (I use this for the calculation of a 6 period exponential moving average) but instead it returns 0.
Thank you very much in advance!
API Support
Post subject: Re: error when assigning result of a division operation
I just can not understand why the following lines of code returns the result "k=0.0
Because java performs integer division with integers, you either need to operate with double values or make explicit cast, thus either k=2d/(6d+1d); or k=2.0/(6.0+1.0);