Domanda

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?

È stato utile?

Soluzione

That is double's precision. You could use

cookies = Math.round( cookies * 100.0 ) / 100.0;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top