Samjack
Samjack

Reputation: 188

Operation with the same result every time

I'm trying to do this operation

y = (float) ((-1/1300)*(xsec))+40;

where xsec is x to the second.
With this function double xsec = Math.pow((double)x, 2.0);
and after customized float in this way xsec = (float) xsec; and y is float.

So when i do the first operation the result is every time 40.0! I checked that xsec change, but even if xsec change the result is the same, 40.0! I suppose that 1/1300 is an operation with too many decimal digits.
How can this happen?

Upvotes: 0

Views: 126

Answers (1)

Zong
Zong

Reputation: 6230

-1/1300 produces 0 under integer division. Use -1.0/1300.

Upvotes: 5

Related Questions