I have this function.
Calculations.add(this, //CONTEXT
function () { //CALUCATE
this.position.x += (this.movementSpeed.x / 10);
},
function () { //HAVE CALCULATED
return (this.position.x === (tempX + this.movementSpeed.x));
}
);
I have run the result, but sometime the result is wrong. Cause I know that if it calculate 10 times, then the the HAVE CALCULATED whould be true.
But sometimes it never is… And that kills my app.
Let us say that the result should give 138, then after the calculation it give me 138.000000000006 which is not 138 and the HAVE CALCULATED is false..
How can I manage this= I can’t use round, because it should be able to return 138.5, if the end-result is that.
Hope you understand my question.
You should never compare floating point values this way. (The link from Waleed Khan in the comments gives a good explanation why this happens)
Instead you can do something like this to check equality of
aandb: