Re: Round
| From: | Daniel Brown | Date: | Wed, 29 Aug 2007 16:48:14 +0000 |
| Subject: | Re: Round | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261467@lists.php.net to get a copy of this message | ||
On 8/29/07, Zoltán Németh <znemeth@alterationx.hu> wrote:
> > Think this through before you respond...
> >
> > Try this
> >
> > <?php
> > var_dump( round(-0.26) );
> > var_dump( abs( round(-0.26) ) );
> > var_dump( round(-1.26) );
> > var_dump( abs( round(-1.26) ) );
> > ?>
> >
> > does this give you the desired results?
> >
> > What if I expected -1 for the last answer?
It didn't take much thinking this time.... if you were expecting
-1 for the last answer, you'd be wrong. ;-P
The very nature of abs() is to return an absolute number, which is
never a negative.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.