Skip to content

Rounding regression with calculated values. #17136

@turbo124

Description

@turbo124

Description

https://3v4l.org/KWK15

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions