所以有人问我为我的家庭作业的一部分蒙上浮点数在到整数PHP。问题是根据php.net没有这样的演员是可能的,我自己也找不到这个问题背后的概念。PHP类型转换
考虑以下几点:
$float = 1.92;
$float += 2;
这将刚刚替补他们造成3.92作为输出。
至于我能看到的可能(或者说允许)铸件如下:
允许的强制转换有:
(int), (integer) - cast to integer
(bool), (boolean) - cast to boolean
(float), (double), (real) - cast to float
(string) - cast to string
(array) - cast to array
(object) - cast to object
(unset) - cast to NULL (PHP 5)
它是某种诡计的那他们向我们介绍了或者该任务是无效的?
[PHP意外的浮点结果到int类型转换]的可能重复(http://stackoverflow.com/questions/3385685/php-unexpected-result-of-float-to-int-type-cast) –
I不想转换它,而是输入。 –
那么,为什么你认为你不能将一个浮点数转换为整数? –