基本上我有两个变量:
double halfWidth = Width / 2;
double halfHeight = Height / 2;
因为它们被除以 2,所以它们要么是整数,要么是小数。我如何检查它们是整数还是 .5?
最佳答案
您可以使用 modf
,这应该足够了:
double intpart;
if( modf( halfWidth, &intpart) == 0 )
{
// your code here
}
关于c++ - 如何检查 double 是否有小数部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16533936/