Re: mathematical discrepancies

From: Date: Thu, 14 Aug 2008 13:09:52 +0000
Subject: Re: mathematical discrepancies
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-45221@lists.php.net to get a copy of this message
Well, yes, it is expected behavior. I think you're confusing the abs() with the round() function (see Evert's answer earlier). abs(-1.05) = 1.05 round(-1.05) = -1 abs(1.35) = 1.35 round(1.35) = 1 hth, Yves ----- Original Message ----- From: "Andrew Martin" <sublimino@gmail.com> To: <php-db@lists.php.net> Sent: Thursday, August 14, 2008 7:55 AM Subject: [PHP-DB] mathematical discrepancies
Hello, Can anybody shed any light on this behaviour please? PHP Version 5.2.5 on XP $a = 1754.00 ; $b = 1754.03 ; $diff = abs($b) - abs($a);
echo "$diff<br/>";     //output: 0.03
$a = 1754.00 ; $b = 1754.09 ; $diff = abs($b) - abs($a);
echo "$diff<br/>";     //output :0.0899999999999
$a = 1754.01 ; $b = 1754.02 ; $diff = abs($b) - abs($a);
echo $diff;     //output: 0.00999999999999
Is this expected behaviour? Can anybody reproduce this? Many thanks, Andy -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#45221) next »