PHP 有没有办法四舍五入到最接近的 50,000?
我已经调查了 round,但文档没有建议一种方法来做到这一点,而且看起来它似乎只是用于向上/向下舍入到最接近的数字。谢谢。
/**
* 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
除以要舍入的数字,进行舍入,然后再次乘以它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)