Introduction: This is a detailed page of the floating point Precision warning in PHP. It introduces the related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 336630 'rolling = 'no'>
This is the prompt in PHP document:
A simple decimal score is like0.1Or0.7It cannot be converted to an internal binary format without losing a little bit of precision.
Floor (0.1 + 0.7) * 10)Return7Instead8,
(INT) (0.1 + 0.7) * 10) returns 7 instead of 8.
The explanation for this phenomenon is "because the internal representation of the result is actually similar.7.9 ".
So the conclusion is:
Therefore, never believe that the result of a floating point number is accurate to the last digit, or compare whether the two floating points are equal.
Never forcibly convert an unknown score to an int.
(INT) round (0.1 + 0.7) * 10) This seems safe.
The BC math function is used for numerical accuracy when a large number of multiplication or division is performed or the center value is float.
More articles on "floating point Precision warning in PHP"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/336630.html pageno: 10.