php中intval 为什么输出 57

2025-03-01 03:41:22
推荐回答(1个)
回答1:

PHP 的 Manual 里有写,是 intval() 这个函数的问题,采用的是“截断”法取整。
其实如果你直接输出 0.57*100 结果是正确的。

intval converts doubles to integers by truncating the fractional component of the number.

When dealing with some values, this can give odd results. Consider the following:

print intval ((0.1 + 0.7) * 10);

This will most likely print out 7, instead of the expected value of 8.

For more information, see the section on
floating point numbers in the PHP manual我推荐你去后盾人上面看看里面有很多关于这类php之类的教学视频哦哦视频讲解高质量