Excel has the MROUND function which rounds a number up/down to a given multiple.
=MROUND(600, 400) //--> 800
=MROUND(14,4) //--> 16
=MROUND(0.5,2) //--> 0
What is the equivalent function for PHP?
If there is none, how would you do it?
You can achieve the same effect by dividing by the denominator, rounding it, then multiplying it again by the denominator. Eg:
function roundTo($number, $to)
{
return round($number/$to, 0)* $to;
}
echo roundTo(87.23, 20); //80
echo roundTo(600, 400) // 800
echo roundTo(14,4) // 16
echo roundTo(0.5,2) // 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With