rfc:new_rounding_modes_to_round_function

This is an old revision of the document!


PHP RFC: Add 4 new rounding modes to round() function

Introduction

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

- PHP_ROUND_CEILING, - PHP_ROUND_FLOOR, - PHP_ROUND_AWAY_FROM_ZERO, - PHP_ROUND_TOWARD_ZERO.

Two first comments on the documentation page of the round() function are related to the missing modes of rounding. The first comment has a outstanding 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

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() roundes the number by given precision.

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 not straightforward and thus I restrained from using them.

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.

Add 4 new rounding modes to function round()?
Real name Yes No
Count: 0 0

Implementation

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/new_rounding_modes_to_round_function.1693437057.txt.gz · Last modified: 2023/08/30 23:10 by jorg_sowa