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
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.
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));
}
Please check for
if(empty($xmlArray->{'MDD'})){
$autoStraObj->setRisk(' - ');
}else{
$autoStraObj->setRisk(round(($xmlArray->{'Pips'} / $xmlArray->{'MDD'}), 10));
}