The floating point precision warning in PHP is a prompt in PHPdocument: a simple decimal score is like 0.1 or 0.7 and cannot be converted to an internal binary format without losing a little precision. Floor (0.1 + 0.7) * 10 )?? Return 7 instead of 8, (int) (0.1 + 0.7) * 10 )? Return 7 instead of 8 .? The explanation for this phenomenon is "the result contains a warning about the floating point precision in PHP.
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 )? Return 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.
?