Search code examples
phpnegative-number

calculate value & display negative number ( if applicable )


OK so in the DB table I have 2 cols & values Lets say open = 1.23450 & close = 1.23400

now here is the PHP code that I am trying to use for the calculation

 $pips = abs($value['close'] - $value['open'])*1;

This should return a value of -0.0005 However it just simply returns value 0 when I echo $pips


Solution

  • If number of digits after the decimal are fixed ( say 5 digits precision)

     $pips = abs($value['close']*100000 - $value['open']*100000);
     $pips = $pips/100000;