Hi,
The reason you are getting different output when you believe you should be getting the same is that you are actually using two different types of variables.
ceil() takes a float as input and outputs an integer, however, if the input is an integer, it does not need to do any operation and simply returns what you passed into it.
Therefore:
[php]
$var = “5”; //this is an INT
echo “ceil: “.ceil($var).”
”; // result is 5, because ceil() was passed an INT, and did nothing
$var = 294.85 / 58.97; // value comes to 5, but because of the decimal points, even though no decimal places are shown, this $var is no longer an INT
echo “var: $var
”; // echoes 5, because the value of $var is 5
echo “ceil: “.ceil($var).”
”; // the ceil value is 6 … because it was passed 5 as a float and ran it’s normal operation of rounding up
[/php]
I believe you’re better off using round, and if you only want to round up and never down try using something like this:
[php]
echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 - tells round to round 9.5, 0 decimal places, and if the value is half or higher, round up, otherwise, round down
[/php]
Hope this helps!
Robert