可以这样做吗?
double variable;
variable = 5;
/* the below should return true, since 5 is an int.
if variable were to equal 5.7, then it would return false. */
if(variable == int) {
//do stuff
}
我知道代码可能不会这样,但是是怎么回事呢?
最佳答案
或者你可以使用模运算符:
(d % 1) == 0
关于java - 如何测试 double 是否为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9898512/