Take the State of PHP 2026 Survey →

New 4 rounding modes to round() function View as Markdown

Implemented (PHP 8.4)
Authors
Jorg Sowa jorg.sowa@gmail.com
Date
2023-08-31
Target
PHP 8.4
Implementation
https://github.com/php/php-src/pull/12056
Source
wiki.php.net/rfc/new_rounding_modes_to_round_function

Votes

Implement 4 new rounding modes to `round()` function closed
Yes
19
No
0
19 voters
ashnazg Yes 2023-11-22 19:12
bukka Yes 2023-11-16 14:59
crell Yes 2023-11-20 20:33
derick Yes 2023-11-17 10:19
galvao Yes 2023-11-24 00:33
girgias Yes 2023-11-16 00:10
joey Yes 2023-11-16 12:52
kalle Yes 2023-11-16 01:29
levim Yes 2023-11-16 16:12
mbeccati Yes 2023-11-20 08:35
nicolasgrekas Yes 2023-11-16 22:43
nielsdos Yes 2023-11-17 22:55
ocramius Yes 2023-11-18 13:41
petk Yes 2023-11-17 20:57
ramsey Yes 2023-11-20 20:13
santiagolizardo Yes 2023-11-18 18:10
sergey Yes 2023-11-26 10:57
theodorejb Yes 2023-11-16 17:28
timwolla Yes 2023-11-18 10:56
Create aliases for Intl extension constants ROUND_UP and ROUND_DOWN: ROUND_AWAY_FROM_ZERO and ROUND_TOWARD_ZERO closed
Yes
10
No
6
16 voters
ashnazg Yes 2023-11-22 19:12
bukka No 2023-11-16 14:59
crell Yes 2023-11-20 20:33
derick No 2023-11-17 10:19
galvao Yes 2023-11-24 00:33
girgias Yes 2023-11-16 00:10
joey Yes 2023-11-16 12:53
kalle No 2023-11-16 01:30
levim No 2023-11-16 16:12
mbeccati Yes 2023-11-20 08:36
nicolasgrekas Yes 2023-11-16 22:43
ocramius No 2023-11-18 13:41
ramsey Yes 2023-11-20 21:21
santiagolizardo No 2023-11-18 18:11
sergey Yes 2023-11-26 10:57
theodorejb Yes 2023-11-20 21:41

Discussions on the mailing list

[RFC] [Discussion] Add 4 new rounding modes to round() function
by Jorg Sowa · 15 messages
[VOTE] [RFC]
by Jorg Sowa · 3 messages
[RFC] [VOTE] Add 4 new rounding modes to round() function
by Jorg Sowa · 10 messages
Incorrect terminology usage for rounding modes of round()
by Gina P. Banyard · 6 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC

Introduction

The RFC proposes to add 4 new modes to the round() function.

Note: The aforementioned constants have been transformed into an enum in a follow-up RFC.

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.

Creating two aliases of constants from Intl extension to have consistent naming for rounding modes:

  • ROUND_TOWARD_ZERO (equivalent of PHP_ROUND_TOWARD_ZERO) alias of ROUND_DOWN
  • ROUND_AWAY_FROM_ZERO (equivalent of PHP_ROUND_AWAY_FROM_ZERO) alias of ROUND_UP

Backward Incompatible Changes

None

Proposed PHP Versions

8.4

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.

Those constants would be deprecated and replaced with their corresponding aliases: ROUND_TOWARD_ZERO and ROUND_AWAY_FROM_ZERO.

Why not the enum implementation for the rounding modes?

As this is extension of the existing modes we should add complementary modes to the existing constants instead implementing new Enum. This way enum is an addition to the new constants and is not included into this RFC.

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-11-15 and will end on 2023-11-30 00:00 GMT.

Vote: Implement 4 new rounding modes to `round()` function — Yes: 19 · No: 0 (closed)


If the first voting is not accepted the result of the second voting will be ignored.

Vote: Create aliases for Intl extension constants ROUND_UP and ROUND_DOWN: ROUND_AWAY_FROM_ZERO and ROUND_TOWARD_ZERO — Yes: 10 · No: 6 (closed)

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.