Wednesday, 3 June 2015

round to the nearest multiple


This function will round numbers to the nearest multiple. For example if you want to round numbers to the nearest 100, and you have 55.5 it will round to 100. 
<?php function multiple_round($value$to){ 
    
$opt $value $to; 
    
$opt round($opt,0); 
    
$opt $opt $to; 
    return 
$opt; 
} 

echo 
multiple_round(500,1000); // Returns 1000 echo multiple_round(499,1000); // Returns 0 

echo multiple_round(49,10); // Returns 50 echo multiple_round(599,10); // Returns 600 ?>

0 comments:

Post a Comment