Reputation: 553
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?
Upvotes: 1
Views: 193
Reputation: 324610
The value of the precision
setting 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.
Upvotes: 5