I’m trying to do some basic calculation stuff in my android app to compare a Date.getTime() value with some calculated stuff.
The calculation I do during a database query is:
long minus = pauseDays * 24 * 60 * 60 * 1000;
So basically I calculate the millisecond-value of pauseDays. If pauseDays gets bigger (I’m talking about 90 days or so), something strange happens. The result of the calculation is a negative number.
The weird thing is, that the result should be 7776000000, so it should be way smaller than Long.MAX_VALUE. Could anybody explain to me why I get a negative number here?
The reason is probably because
pauseDaysis aninttype, right? Then you are multiplying it by another bunch ofints, then converting it tolong.Consider this:
The output of this is:
Notice that the first
long minususes integers to generate its value. The secondlong minusLuses all long integer values.