Re: Round
| From: | Zoltán Németh | Date: | Wed, 29 Aug 2007 16:38:46 +0000 |
| Subject: | Re: Round | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261466@lists.php.net to get a copy of this message | ||
2007. 08. 29, szerda keltezéssel 09.29-kor Jim Lucas ezt írta:
> Daniel Brown wrote:
> > On 8/29/07, Richard Heyes <richardh@phpguru.org> wrote:
> >> Koen van den Boogaart wrote:
> >>> No, I want it to go to float(0), so minus the minus. "-0" doesn't
> >>> exist in
> >>> math, as far as I know. Probably a precision thing.
> >> Ok, then try abs() first then.
> >>
> >> --
> >> Richard Heyes
> >> +44 (0)844 801 1072
> >> http://www.websupportsolutions.co.uk
> >>
> >> Knowledge Base and HelpDesk software
> >> that can cut the cost of online support
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
> > Richard (Heyes) is right.
> >
> > <?php echo var_dump(abs(round(-0.26)))."\n"; ?>
> >
> > Tested on 5.0.4 and 5.2.3.
> >
> 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?
why would you expect -1 for the last one?
abs(-1) should return 1 AFAIK
that's what the above code produces too.
greets
Zoltán Németh
>
>
> --
> Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
>