PHP 中四舍五入到最接近的 50,000 [英] Round up to the nearest 50,000 in PHP
本文介绍了PHP 中四舍五入到最接近的 50,000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 PHP 中四舍五入到最接近的 50,000?
Is there a way to round up to the nearest 50,000 in PHP?
我已经调查过了,但文档没有建议这样做的方法,而且看起来好像只是为了向上/向下四舍五入到最近的数字.谢谢.
I've investigated round, but the docs don't suggest a way to do this, and it looks as though it is only for rounding up/down to the nearest numner. Thanks.
推荐答案
/**
* 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
除以要舍入的数字,进行舍入,然后再乘以它.
Divide by the number you want to round against, do the rounding, then multiply by it again.
这篇关于PHP 中四舍五入到最接近的 50,000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文