I'm attempting to make a game in which I need to store a large number. I am currently using a int but the number keeps turning negative. Is there a reason this would be happening?
Asked
Active
Viewed 35 times
-3
-
With some code sample you'll get an answer. – ranieribt Mar 22 '19 at 18:28
-
1Its likely that you may be encountering an integer overflow, but theres no way to figure that out unless you show us the code. – Mercury Platinum Mar 22 '19 at 18:30
-
2Possible duplicate of [How does Java handle integer underflows and overflows and how would you check for it?](https://stackoverflow.com/questions/3001836/how-does-java-handle-integer-underflows-and-overflows-and-how-would-you-check-fo) – Zoe Mar 22 '19 at 18:55
1 Answers
1
This could be because your value is exceeding the range that a int
can store. Try using the long
variable rather then int

asr9
- 2,440
- 1
- 21
- 37

Austin Knaak
- 11
- 1