math - PHP (int) / braces mathematically wrong - Possible Bug? -
this question has answer here:
me , colleges discussing following problem, , although came theories still seeing odd...
<?php echo (int) ((0.1 + 0.7) * 10); ?>
outputs 7
whilst
<?php echo (int) (0.1 + 0.7) * 10; ?>
outputs 8 (as expected , output if calculator)
could (int) causing issue here? have idea?
thanks lot , day!
the cast integer (and related rounding error) occurs @ different point in formula
calculate 0.1 plus 0.7, multiply 10 , cast integer;
with expected rounding error, should result in 7
against
calculate 0.1 plus 0.7, cast integer, , multiply 10
casting 0.1 + 0.7 (ie 0.8) integer should give 0, multiplied 10 still 0
Comments
Post a Comment