Possible Duplicate:
PHP Math Precision
The following php code outputs 7 but I expect 8. Why the difference?
<?php echo (int)((0.1+0.7)*10); ?>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.