Home  >  Article  >  Backend Development  >  php round函数bug

php round函数bug

WBOY
WBOYOriginal
2016-06-06 20:14:551186browse

算增长率的时候,用round来截取小数点后两位
但是后来去数据库看数据的时候,大部分数据都可以,但是有一部分出现错误

调试后发现
-8.04554643785644
round后变成
-8.04000000000001

这个bug出现几率还挺高
在另一个脚本中测试,同样的数据正常截取

回复内容:

算增长率的时候,用round来截取小数点后两位
但是后来去数据库看数据的时候,大部分数据都可以,但是有一部分出现错误

调试后发现
-8.04554643785644
round后变成
-8.04000000000001

这个bug出现几率还挺高
在另一个脚本中测试,同样的数据正常截取

不算bug吧,凡是涉及到浮点数问题肯定有精度误差的,用的时候注意一下就行了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn