Question

So I'm making a cookie clicker clone in java (shame on me) and for one thing, I need the double to increase by .1 for each cursor you own. The code looks like this (cookies is a double, and all other values are ints):

cookies = cookies + (cursors*.1+grandmas/2+farms*4+factories*10);

however, when this outputs, it outputs numbers like 2.399999999999999 instead of 2.4. What is going on?

Was it helpful?

Solution

That is double's precision. You could use

cookies = Math.round( cookies * 100.0 ) / 100.0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top