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 fo
/**
* 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.
Try this:
$number = "78921";
$round = round($number / 50000) * 50000;
How about this:
$number = ceil($value / 50000) * 50000;