有没有办法在 PHP 中四舍五入到最接近的 50,000?
我已经调查过了,但是文档没有建议这样做的方法,而且看起来它似乎只是用于向上/向下舍入到最接近的数字。谢谢。
/**
* 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
除以要舍入的数字,进行舍入,然后再乘以。
这个怎么样:
$number = ceil($value / 50000) * 50000;
尝试这个:
$number = "78921";
$round = round($number / 50000) * 50000;