Re: More math fun

From: Date: Tue, 12 Aug 2008 21:59:31 +0000
Subject: Re: More math fun
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278012@lists.php.net to get a copy of this message
Jay Blanchard wrote:
abs($balanceTest) = 15.22 abs($oldLineArray[16]) = 15.22 $diff = abs($balanceTest) - abs($oldLineArray[16]); echo abs($diff) . "\n"; 1.7763568394E-15 WTF? This should be a big fat 0
I do not see how it makes any difference if $balanceTest and $oldLineArray[16] are strings in the beginning. In line that does the subtraction, they would have been converted to floats automagically by abs(). If you look at the manual for this function, you will see that the returned value is either a float or integer bases on the input type. Float would return a float. Anything else would return a integer. BTW - if I setup the following: <?php $balanceTest = '15.22'; # A string $oldLineArray[16] = 15.22; # A float $diff = abs($balanceTest) - abs($oldLineArray[16]); echo abs($diff) . "\n"; echo gettype(abs($diff)) . "\n"; # 1.7763568394E-15 ?> I get 0 and 'double' -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#278012) next »