

new_rounding_modes_to_round_function
source link: https://wiki.php.net/rfc/new_rounding_modes_to_round_function
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PHP RFC: Add 4 new rounding modes to round() function
Introduction
The RFC proposes to add 4 new modes to the round() function.
Two first comments on the documentation page of the round() function are related to the missing modes of rounding. The first comment has an outstanding number of 309 votes.
Moreover, the NumberFormatter already implements 4 new proposed modes known as ROUND_CEILING, ROUND_FLOOR, ROUND_DOWN, ROUND_UP.
Proposal
Adding 4 new constants for the rounding modes of function round():
- PHP_ROUND_CEILING - rounds num to the nearest integer bigger than num,
- PHP_ROUND_FLOOR - rounds num to the nearest integer lower than num,
- PHP_ROUND_AWAY_FROM_ZERO - rounds num away from zero,
- PHP_ROUND_TOWARD_ZERO - rounds num towards zero.
Backward Incompatible Changes
Proposed PHP Versions
Questions
Why not use functions ceil() and floor()?
The functions ceil() and floor() round numbers to the full integer, while the function round() rounds the number by given precision. Implementing new rounding modes we get equivalent of those functions using round() with 0 as precision.
ceil($number) === round($number, 0, PHP_ROUND_CEILING); //true floor($number) === round($number, 0, PHP_ROUND_FLOOR); //true
Why not the names PHP_ROUND_UP and PHP_ROUND_DOWN?
Such constants already exist in the NumberFormatter and represent rounding modes 'away from zero' and 'toward zero'. However the names rounding up and down are ambiguous. They may be easily confused with the rounding ceiling/floor, while the terms away from/toward zero are distinct.
Proposed Voting Choices
As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted.
Voting started on 2023-09-x and will end on 2023-09-x.
Implementation
GitHub pull request: https://github.com/php/php-src/pull/12056
References
Links to external references, discussions or RFCs
Rejected Features
Keep this updated with features that were discussed on the mail lists.
Recommend
-
29
README.md Squircle
-
34
Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
-
15
SQL Server Rounding Functions - Round, Ceiling and Floor By: Jeremy Kadlec | Updated: 2021-07-20 |
-
8
Rounding in Java – Math.Round, Math.Floor, Math.CeilWe have decimal values in java, but sometimes there is a need to round them. It is important to remember which function should be used according to the requirements. So In...
-
13
WatchOS 9 adds new modes and watch facesKyle WiggersTue, June 7, 2022, 2:53 AM·2 min readDuring a keynote at Apple's Worldwide Deve...
-
5
AdvertisementClose‘Warzone 2.0’s’ Gulag, proximity chat, new modes and more...
-
3
1. General passing of arguments The Go language supports calling functions by passing arguments sequentially, as shown in the following example function. // ListApplications Query A...
-
9
round-decimal Decimal rounding with ULP. Warning Work in process Installation npm install -D round-decimal
-
13
Gotham Knights: New “Heroic Assault” e “Showdown” modes are available WB Games Montreal released this Tuesday (29), a major update for Gotham Knig...
-
8
.NET 8 introduced major and exciting changes to Blazor, unified its hosting models, and adopted server-side rendering. In this post, we will give you an overview of these new additions and describe how you can leverage them in your Blazor apps.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK