MySQL Forums
Forum List  »  PHP

Re: Decimal Compare not working
Posted by: Hans Brost
Date: June 16, 2014 08:20PM

There are some other considerations and it won't work unless you do the following.

Say you set local variables from a DB Row like this (both values are the same (-0.00003) in the DB):

$MstMACD = $MstNxtRow['MACD']; is -0.00003
$MstMACDPrev = $MstNxtRow['MACDPrev']; is -0.00003

$MstD1Pri is .001
$MstMA12 is .00103,
$MstMA26 is .00106

Then calculate a new $MstMACD (which will also calculate to -0.00003):

$WkEMA = (($MstD1Pri - $MstMA12) * 0.1538461) + $MstMA12;
$MstMA12 = round($WkEMA, 5);

$WkEMA = (($MstD1Pri - $MstMA26) * 0.074074) + $MstMA26;
$MstMA26 = round($WkEMA, 5);


$MstMACD = $MstMA12 - $MstMA26;

And to all appearances $MstPrevMACD is the SAME as $MstMACD, a comparison of the 2 for equality will FAIL unless you do this:

$WkEMA = $MstMA12 - $MstMA26;
$MstMACD = round($WkEMA, 5);

In other words, it's not sufficient to round the MA12 and MA26 to 5 decimals, and expect the result of a subtraction to also be 5 decimal places.

Clear as mud I'm sure.....lol.......z

Options: ReplyQuote


Subject
Written By
Posted
June 16, 2014 12:12PM
Re: Decimal Compare not working
June 16, 2014 08:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.