0

I am using symfony 1.1 to read an API and store the values in DB

if(($xmlArray->{'MDD'} == 0) || ($xmlArray->{'MDD'} == '0') ){  
       $autoStraObj->setRisk(' - ');
    }else{
       $autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
    }

For Some Records, the above code results with

Warning: Division by zero in.... Not sure, that is the issue here

RONE
  • 5,415
  • 9
  • 42
  • 71

3 Answers3

1

First check $xmlArray->{'MDD'} is zero or not.If it is zero for some records then it will give you this error.

if(($xmlArray->{'MDD'} != 0) && ($xmlArray->{'MDD'} != ''))
{
   $autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
}

Or simply

if(!empty( $xmlArray->{'MDD'}) ) {
   $autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
}

Or as cHao said try like

if (+$xmlArray->{'MDD'} != 0) {
   $autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

Because for some records $xmlArray->{'MDD'} equals zero.

To avoid this - first check if there is a 0 and do not divide, just show "0" instead.

Paul Denisevich
  • 2,329
  • 14
  • 19
0

Please check for


if(empty($xmlArray->{'MDD'})){  
       $autoStraObj->setRisk(' - ');
    }else{
       $autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
    }
Parixit
  • 3,829
  • 3
  • 37
  • 61