<?php print (int)((0.1 + 0.7) * 10); ?> 

Why it turns out 7 and not 8?

  • Perhaps because (int) does not round, but discards the fractional part. - alexlz
  • @alexlz, this is true, but everything is much worse than $ v = (0.1 + 0.7) * 10; echo "$ v \ n"; echo (int) $ v. "\ n"; echo (int) "$ v". "\ n"; will issue 8 7 8 - zb '23
  • @eicto And how is it worse? I do not see anything strange in the example. Although it somehow reminds a slingshot with a laser sight ... - alexlz

1 answer 1

Everything is described in detail: The layout of the float in memory