-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Labels
Description
Description
This demonstrates the problems with the new implementation of rounding.
PHP 8.x
round(33.325,2) => 33.33
However this changes when using any form of arithmetic
25 x 1.333
Returns as 33.325 from PHP 8.x
However we now get divergence when we consider this
round((25x1.333),2)
PHP 8.4 => 33.32
PHP <= 8.3 => 33.33
33.325 represented as a floating point is
33.324999999999996
Which the new approach to rounding believes that the intention here is to round down.
I believe this is a regression and if not at the very least should be treated like a breaking change.
Whilst the old approach was not perfect, it provided predictable results. I believe a better approach would be to consider the use of an epsilon value in order to coerce the float based on the range of potential error.
PHP Version
PHP 8.4
Operating System
No response