PHP rounding issue - Is this a bug? [duplicate]
Possib开发者_运维问答le Duplicate:
Floating point inaccuracy examples
If i say round(152.77499999999998,2) the answer becomes 152.78. Should it not look at the 3rd number after the decimal point and if it is 5 or higher round up and if it is 4 or lower round down, hence the answer should be 152.77?
Thanks
You should do:
round(152.77499999999998 * 100)/100
to get the exact number! :)
It is very possible that in whatever internal representation 152.77499999999998 gets folded to it is actually more like 152.77500001754…; and hence the rounding goes up.
What php is going is regular rounding.
This same question was asked here 2 years ago:
http://www.webdeveloper.com/forum/showthread.php?t=247953 (what are the chances?)
精彩评论