-5

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?

1 Answers1

0

That is double's precision. You could use

cookies = Math.round( cookies * 100.0 ) / 100.0;
Syam S
  • 8,421
  • 1
  • 26
  • 36