Re: Stuck... Long day I think.. ;-)

From: Date: Fri, 16 May 2003 23:53:53 +0000
Subject: Re: Stuck... Long day I think.. ;-)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-147996@lists.php.net to get a copy of this message
> > One general rule of thumb is never to test a floating > > point number for equality. > > Ah, I did not know that, thanks. So any suggestions for > how to approach this then? I guess I need to convert > those values to something else and test them?? Right. Probably best to convert to integers (multiply by ten) and convert back for display. You could test the floating point for a range instead, but I think the simplest and fastest is to use integers. For more, see the box labeled: "Floating point precision" at: http://www.php.net/manual/en/language.types.float.php --Frappy. On Friday 16 May 2003 07:43 pm, Brian V Bonini wrote: > On Fri, 2003-05-16 at 19:19, Frappy John wrote: > > > I do the same thing here and it works fine: > > > > > > for($i = 250; $i <= 1000; $i += 250) { > > > $c_val[] = $i; > > > } > > > > . . . > > > > > I'm not seeing the difference in terms of > > > functionality. > > > > One big difference is your protein routine deals with > > decimals (floating point) and your calories routine > > deals with whole numbers (integers). > > > > One general rule of thumb is never to test a floating > > point number for equality. > > Ah, I did not know that, thanks. So any suggestions for > how to approach this then? I guess I need to convert > those values to something else and test them?? > > > > I can not get ($v != $_POST['protein']) to evaluate > > > as true. > > > > I would think it would *always* evaluate as true (i.e. > > always != ). Is that what you meant to say? > > Yup, that's what I meant, like I said, "long day"... ;-)

« previous php.general (#147996) next »