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" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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" <[EMAIL PROTECTED]>
> 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?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to