Re: More math fun
| From: | Robert Cummings | Date: | Wed, 13 Aug 2008 02:40:07 +0000 |
| Subject: | Re: More math fun | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278017@lists.php.net to get a copy of this message | ||
On Tue, 2008-08-12 at 14:59 -0700, Jim Lucas wrote:
> 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'
Yeah, I was probably thinking abs( $balanceTest - $oldLineArray[16] )
versus what was actually present. But either way, I get 0 doing the
above also when I set up the values... so I have no idea how it's not
working for Jay.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP