Re: Mistical 17.49 (possible bug)

From: Date: Wed, 07 Aug 2002 15:14:21 +0000
Subject: Re: Mistical 17.49 (possible bug)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-111520@lists.php.net to get a copy of this message
Floats are not super accurate because (float)1 can be 1.00001 even something like this will not work as expected for ($i=2;$i>=0;$i-=0.05) echo $i."\n"; 2 1.95 1.9 1.85 1.8 1.75 1.7 1.65 1.6 1.55 1.5 1.45 .... 0.45 0.4 0.35 0.3 0.25 0.2 0.15 0.099999999999999 0.049999999999999 Do you see that 0 is not shown. If it is possible to not use floats do not use them. Regards, Andrey ----- Original Message ----- From: "Ipa" <ipa@beta.lt> To: <php-general@lists.php.net> Sent: Wednesday, August 07, 2002 6:02 PM Subject: Re: [PHP] Mistical 17.49 (possible bug) > Rounding is a solution but. > > echo (995 % 100) . "<br>"; // result 95 > echo (((995 / 100) * 100) % 100) . "<br>"; // result 94 > echo ((995 / 100) * 100) . "<br>"; // result 995, not 994.99999999 > > > > > Rounding. > > 17.49*100 can be 1748.99999999, and the rest is 48 > > > > Andrey > > > > ----- Original Message ----- > > From: "Ipa" <ipa@beta.lt> > > To: <php-general@lists.php.net> > > Sent: Wednesday, August 07, 2002 5:46 PM > > Subject: [PHP] Mistical 17.49 (possible bug) > > > > > > > Good day. > > > > > > Can anybogy explain this trick. > > > > > > <?php > > > echo (1749 % 100) . "<br>"; > > > echo ((17.49 * 100) % 100) . "<br>"; > > > ?> > > > result should be the same isn't it ? > > > but output is : > > > > > > 49 > > > 48 > > > > > > ???? ;)))) > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#111520) next »