@scragarNov 07.2008 — #huh, I figured it'd be better to go for something like: [code=php]function my_round($number, $scope=0.5){ $fraction = fmod($number, $scope); if($fraction < $scope/2) return $number - $fraction; else return $number + ($scope - $fraction); }[/code]I know it's going to use more CPU power, but honestly, I like how much more flexible it is.
@SodbusterNov 07.2008 — #Flexibility is nice, of course, but your function transforms, for example, 15.2 to 15 and 15.59 to 15.5, which apparently is not what OP was after. And if he wishes to alter my function to make it more flexible, he's certainly welcome to.
@scragarNov 07.2008 — #Well if you always want to round up, you could just comment out a few lines: [code=php] function my_round($number, $scope=0.5){ $fraction = fmod($number, $scope); // if($fraction < $scope/2) // return $number - $fraction; // else return $number + ($scope - $fraction); }[/code] And if you ever wanted rounding down, it can be done with a similar edit: [code=php] function my_round($number, $scope=0.5){ $fraction = fmod($number, $scope); // if($fraction < $scope/2) return $number - $fraction; // else // return $number + ($scope - $fraction); }[/code] but right now I'm defending code I knew wasn't needed, so ignore me if you want ?