|
Posted by Jerry Stuckle on 02/22/07 19:36
Johannes Vogel wrote:
> Hi
>
> Anonymous wrote:
>> Jerry Stuckle wrote:
>>> $num = int($num);
>> I would advise against type casting. It can produce strage results under
>> some circumstances.
>> He would be better of using $num = floor($num), that's what the function
>> is here for.
>> ceil() always rounds up, floor() always rounds down, round() rounds
>> according to mathematical rules (down on .0 to .4, up on .5 to .9
>
> What's about minus values?
> We don't know what the OP would like to get.
>
> floor(-2.8) => -3
> (int)-2.8 => -2
>
> HTH, Johannes
int(-2.8) is -2, as you indicated. And the operator indicated he wanted
to truncate the value, so floor() would in this case provide an
incorrect value.
Now if he said he wanted the next lower integer, your solution would be
correct.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|