I've already noticed that simple multiplication in javascript sometimes gives incorrect results. By incorrect I don't mean floating value problem (2.999999 instead of 3) I mean absolutely incorrect result i.e. 2.6581 instead of 44.919283.
I tried to recreate the situation in short lines of code but I didn't manage to do it. I only notice these errors in my whole program.
For example I have these lines:
console.log('myHighestBuy = ' + myHighestBuy);
console.log('theirLowestSell = ' + theirLowestSell);
if ((theirLowestSell * 0.85) < myHighestBuy){
console.log('If condition is true');
offerDeal(name, theirLowestSell, MarketPrice, myHighestBuy)
} else {
console.log('Not calling offerDeal()');
}
What I have noticed, that once it has called offerDeal()
function despite the fact it shouldn't had to.
Correct case console logs:
myHighestBuy = 16.22
theirLowestSell = 27.78
Not calling offerDeal()
But once I had in my console this:
myHighestBuy = 16.22
theirLowestSell = 27.78
If condition is true
Why is it possible? Is it if condition failure or multiplication error?