+ 8
whu var_dump(0.1 + 0.2 == 0.3); return false
6 Answers
+ 10
I'm no expert in PHP, but I'm guessing it has to do with floating-point values being approximations. So in other words: maybe 0.3 is actually stored as 0.30000000003.
+ 10
Because float numbers have a specific accuracy of their representation. You can find more info here: http://php.net/manual/en/language.types.float.php
Hope it helps you.
+ 4
Follow this link:
https://stackoverflow.com/q/588004/9166287
+ 3
So in this case, what is the best way to compare for equality? a) multiplying each by 10 or 100 and casting to integers or b) checking if the sum on the left lies within a small tolerance of the value on the right hand side?