Saturday, July 20, 2013

Round up to multiple in php


Here is a simple function that will round a number up to a given multiple. may this help you

<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

function roundUpToMultiple( $number, $multiple)
{
    return ceil( $number/$multiple ) * $multiple;
} 


?>


Example Usage
<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

echo roundUpToMultiple( 12, 7 );

?>

No comments:

Post a Comment