Java – unexpected result in long / int partition

I have such value:

long millis = 11400000;
int consta = 86400000;
double res = millis/consta;

The question is: why is res equal to 0.0 (not about 0.131944)? It is stored in double, so there should be no rounding right?

Solution

When you use binary operators, the two parameters should be of the same type and the results will be in their types When you want to split (int) / (long), it becomes (long) / (long) and the result is (long) You should do (double) / (long) or (int) / (double) to get double results Since double is int and long, int and long will become double in (double) / (long) and (int) / (double)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>