Thursday, 20 July 2017

Do not understand how this simple php code works






Possible Duplicate:
PHP Math Precision






The following php code outputs 7 but I expect 8. Why the difference?






Answer



Because due to inaccurate floating point representations, 0.1+0.7 is not exactly equal to 0.8. It might be some very tiny bit less than that. And when you use int(..), it truncates it to 7.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...