我有以下计算:
$this->count = float(44.28)
$multiple = float(0.36)
$calc = $this->count / $multiple;
$calc = 44.28 / 0.36 = 123
现在我想检查我的变量 $calc
是否为整数(有小数)。
我尝试执行 if(is_int()) {}
但它不起作用,因为 $calc = (float)123
。
也试过这个-
if($calc == round($calc))
{
die('is integer');
}
else
{
die('is float);
}
但这也不起作用,因为它在每种情况下都返回 'is float'
。在上面的例子中,这不应该是真的,因为 123 与四舍五入后的 123 相同。
最佳答案
关于PHP检查是否是整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22607441/