PHP中最接近的50,000

Dav*_*ard 0 php rounding

有没有办法在PHP中舍入到最接近的50,000?

我已经调查了一下,但是文档没有建议这样做的方法,看起来它只是用于向上/向下舍入到最接近的数字.谢谢.

Mad*_*iha 12

/**
 * Round a number up to the nearest multiple of $n.
 *
 * @param int $int  Number to round.
 * @param int $n    Round to the nearest $n.
 *
 * @return int
 */
function round_up_to_nearest_n($int, $n) {
    return ceil($int / $n) * $n;
}
echo round_up_to_nearest_n(74268, 50000); //Outputs 100000
Run Code Online (Sandbox Code Playgroud)

除以你要反对的数字,进行舍入,然后再乘以它.