Here is the code:
$val = 65.5401000000000001;
return round($val ,2);
I’m expecting to get 65.54, but getting 65.54000000000001.
Why it works this way? And how to get an expected value?
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.
The value of the
precisionsetting in your PHP.ini file is too high. It’s best to keep it at the default 15 to prevent this happening. Basically what you’re seeing is the consequence of floating point numbers not being able to handle real numbers exactly.