Re: More math fun

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux