Rounding to the Nearest Ending Digits
问题 I have the following function that rounds a number to the nearest number ending with the digits of $nearest , and I was wondering if there is a more elegant way of doing the same. /** * Rounds the number to the nearest digit(s). * * @param int $number * @param int $nearest * @return int */ function roundNearest($number, $nearest, $type = null) { $result = abs(intval($number)); $nearest = abs(intval($nearest)); if ($result <= $nearest) { $result = $nearest; } else { $ceil = $nearest - substr(