This question already has an answer here:
这个问题在这里已有答案:
- How to check if number is a decimal? 3 answers
- How to test if a double is an integer 12 answers
如何检查数字是否为小数? 3个答案
如何测试double是一个整数12个答案
I need help with something that can help me check if an int is a decimal. Something like:
我需要帮助,以帮助我检查int是否为小数。就像是:
if(variable == decimal){ //assuming the variable was entered by a user
System.out.println("This number is a decimal.");
} else
System.out.println("This number is an integer.");
}
1 个解决方案
#1
1
If your "variable" value is a double then :
如果您的“变量”值是双倍,那么:
return Math.floor(variable) == variable;
Will return true if "variable" is an Integer.
如果“variable”是Integer,则返回true。
#1
1
If your "variable" value is a double then :
如果您的“变量”值是双倍,那么:
return Math.floor(variable) == variable;
Will return true if "variable" is an Integer.
如果“variable”是Integer,则返回true。