【发布时间】:2014-03-24 10:58:10
【问题描述】:
我有以下计算:
$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 相同。
【问题讨论】:
-
试试
is_int()代替你的代码 -
如果你够潮,也可以使用 Modolo '%'。
-
为什么不使用
is_float? -
为什么首先需要知道?你想做什么?
-
在不知道的情况下设置上限