🔵 4 New Rounding Methods Likely In PHP 8.4

Tom Smykowski
2 min readNov 27, 2023

PHP 8.4 may come with four new methods of rounding numbers for fine-tuned statistical analysis of data

You could say rounding is my pony. Actually after writing the article about it in January i almost forgot about the issue.

The issue being that there’s no onr standard way of rounding. Actually there’s a lot of rounding methods.

Specifically when your value is exactly between two integers, like 8.5, it can be rounded based on several rules that are different in various languages. Some round up (ceiling), down (floor), away from zero, toward zero, to closest even or to closest odd number.

It’s important how you round numbers because it impacts operations on numbers.

For example if you round 1.5 and 2.5 to ceiling you get 2 and 3. An average of the sum of these numbers is 5 / 2 = 2.5.

However, the exact average is 4/2 = 2.

On the other hand when you round to even, you get 2 and 2. Average is 2.

As you can see the value is closer to the real value than rounding to ceiling.

It means that it’s important how you round your data.

--

--

Tom Smykowski

Software Engineer & Tech Editor. Top 2% on StackOverflow, 3mil views on Quora. Won Shattered Pixel Dungeon.