PHP 8.5.0 RC 2 available for testing

Voting

: three plus two?
(Example: nine)

The Note You're Voting On

michaeldnelson dot mdn at gmail dot com
16 years ago
This function will let you round to an arbitrary non-zero number. Zero of course causes a division by zero.

<?php
function roundTo($number, $to){
return
round($number/$to, 0)* $to;
}

echo
roundTo(87.23, 20); //80
echo roundTo(-87.23, 20); //-80
echo roundTo(87.23, .25); //87.25
echo roundTo(.23, .25); //.25
?>

<< Back to user notes page

To Top