Re: Bug?

From: Date: Wed, 08 Aug 2001 22:28:09 +0000
Subject: Re: Bug?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-61921@lists.php.net to get a copy of this message
Hi again, I can't really see much difference in the example you gave? But if it may have something to do with the "casting of an unknown fraction to int", I'll use floor() instead of casting. Same result: floor((8.85-8)*100) = 84 I find that quite odd. I tried a few variations: floor((8.85-8.0)*100.0) = 84 floor((8.84-8)*100) = 83 floor((8.83-8)*100) = 83 floor((8.82-8)*100) = 82 floor((8.85*100)-(8*100)) = 85 For more explicit examples/tests, you can take a look here: http://www.osd.dk/test/test-weirdint.php -Tais "Bjorn Van Simaeys" <cyberplasma@yahoo.com> wrote in message news:20010808161136.72646.qmail@web13407.mail.yahoo.com... > Hello, > I remember there was a warning in the PHP Manual about > this. This is it: > ** Never cast an unknown fraction to integer, as this > can sometimes lead to unexpected results. > ** echo (int) ( (0.1+0.7) * 10 ); // echoes 7! > So do your calculations first, and then echo the > results. This way you get good habits in programming. > And your code will be easier to read as well! > > --- "[Intent A/S] Tais M. Hansen" <tmh@intent.dk> > wrote: > > Hi! > > I just came across this weird thing. Bug? You tell > > me! > > print (int)((8.85-8)*100); > > I would think the line above would print "85". But > > for some reason, it > > prints "84"?? Can anyone tell me why that is?

« previous php.general (#61921) next »