Re: [RFC] [discussion] Correctly name the rounding mode and make it an Enum
Hi
On 6/3/24 18:23, Derick Rethans wrote:
I think it would be really helpful to have a description (and examples)
for each of the rounding modes in the Enum
(https://wiki.php.net/rfc/correctly_name_the_rounding_mode_and_make_it_an_enum#proposal)
— that'd also be great for creating documentation later on.
The RoundingMode
enum will not provide any new rounding modes, thus the existing documentation of rounding modes applies. The corresponding constant names have been mentioned.
Nevertheless I've just added a PHPDoc with a brief definition and examples to each of the enum cases.
Please note: The definition is a little simplified to make it easier to understand the differences on a conceptual level.
It assumes arbitrary precision (which floats do not provide) and it assumes that rounding always rounds to integer values. In reality the round() function supports a specified number of decimal digits, with integer rounding being rounding to 0 decimal digits. An integer rounding function can emulate rounding to a specific number of decimal digits by multiplying the input value by 10**$digits, performing integer rounding, and then dividing by 10**$digits (assuming arbitrary precision).
There's also a helpful table on Wikipedia: https://en.wikipedia.org/wiki/Rounding#Comparison_of_approaches_for_rounding_to_an_integer
Hope this helps.
Best regards
Tim Düsterhus
Thread (27 messages)