Hi all,

The "round" function supports rounding to significant digits before the decimal point which can be very helpful

but unfortunately it's handling everything as floating point numbers which in the end can lead to inaccurate results.

    printf("%d\n", round(987654321098765432, -1) // 987654321098765440 instead of 987654321098765430

To be fair it's also documented as such:

> round — Rounds a float

round(int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float


I would like to propose to change this function to keep the given type and proper handle integers as well:

> round — Rounds a number

/** @template T of int|float */

round(T $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): T


Do you think this could be an acceptable BC-break or should this be a different function?


Thanks,

Marc

Reply via email to