【发布时间】:2012-02-02 06:51:59
【问题描述】:
可能重复:
PHP unexpected result of float to int type cast
int((0.1+0.7)*10) = 7 in several languages. How to prevent this?
谁能给我解释一下???
<?php
echo (int) ((0.1 + 0.7)*10);//displays an output: `7`
?>
我期待看到8,但我得到了7 - 请解释这种行为。
这是PHP 的特殊功能吗?还是我看不懂PHP中的整数类型?
谢谢。
【问题讨论】:
-
为什么要投反对票?你介意解释一下吗?
-
内部呈现不同。你可能有兴趣阅读 PHP 手册page
标签: php