Skip to content

Instantly share code, notes, and snippets.

@Trshant
Last active September 9, 2016 12:01
Show Gist options
  • Save Trshant/f711f18decf5cc38dabe2b4170952688 to your computer and use it in GitHub Desktop.
Save Trshant/f711f18decf5cc38dabe2b4170952688 to your computer and use it in GitHub Desktop.
This gives the number rounded off the next biggest integer. Please see beneath the definition to see what i mean
<?php
function RoundingToNextTop( $num , $rounding ) {
return ( round( $num , (-1 * $rounding ) ) < $num )? round( $num , (-1 * $rounding ))+pow ( 10 , $rounding ) : round( $num , (-1 * $rounding ) ) ;
}
echo RoundingToNextTop( 13.3583 , 1 ) ;
// 20
echo RoundingToNextTop( 103.3583 , 1 ) ;
// 110
echo RoundingToNextTop( 103.3583 , 2 ) ;
// 200
echo RoundingToNextTop( 130.3583 , 2 ) ;
// 200
echo RoundingToNextTop( 1030.3583 , 2 ) ;
// 1100
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment