2

Possible 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

Community
  • 1
  • 1
Pjn2020
  • 517
  • 1
  • 8
  • 18

3 Answers3

1

You should do:

round(152.77499999999998 * 100)/100

to get the exact number! :)

Michael Wright
  • 571
  • 2
  • 2
1

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.

Williham Totland
  • 27,735
  • 5
  • 49
  • 68
0

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?)

Naftali
  • 142,114
  • 39
  • 237
  • 299