Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

sawtooth error when facing zero in the denominator

I have the follwoing hidden variable that has the calculation.
I get Sawtooth error, if someone enter zero for Var12. Did any one faced similar kind of issue and what will be the workaround?

<input name="S44" id="S44" type="hidden" value="[% (Var11/Var12) %]">
asked Jul 20, 2012 by Lawrence Bronze (2,100 points)
retagged Sep 13, 2012 by Walter Williams

1 Answer

+1 vote
Any programming language gives errors when you attempt to divide by zero.  In other words, don't ever do it.  The work around is to check if denominator is zero and in that case return whatever number you expect for that case.  Is it zero or infinity? what do you need for your survey?

<input name="S44" id="S44" type="hidden" value="[% begin unverified perl 
my $Val11 = VALUE("Val11");
my $Val12 = VALUE("Val12");

if ($Val12)
   return $Val11 / $Val12;
   return 0; #your_default_value

end unverified %]">

answered Jul 20, 2012 by Mike Lodder Gold (23,395 points)
Having a physics background myself, I can confirm Mike is correct. Avoid dividing by 0 (multilying is okay). Check the denominator 1st. If zero, you need to make a decision on how to treat your calculation.
Thanks Mike. Your points are valid. Because of the denominator problem respondent cannot move to the next question. Now, I have added condition to skip next question if the denominator is zero.