php中intval 为什么输出 57
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之类的教学视频哦哦视频讲解高质量
其实如果你直接输出 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之类的教学视频哦哦视频讲解高质量
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询