|
|
Am 27.05.2021 um 20:50 schrieb Alain Martel:
> Le 2021-05-27 à 09:14, clipka a écrit :
>> Am 27.05.2021 um 13:20 schrieb Mike Horvath:
>>> Has someone written a macro that rounds a float to the nearest integer?
>>
>> `floor(FOO + 0.5)` should do the trick.
>
> «ceil(FOO - 0.5)» should also work.
In a technical sense, yes. However, values exactly halfway between would
be rounded down, rather than up as per the common convention(*).
(For positive values, that is. For negative values, the common
convention is to round such numbers towards negative infinity, making
the `ceil`-based formula more true to conventional rounding in the
negative domain.)
Post a reply to this message
|
|