Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division By Zero.....when it's not zero!!!

Status
Not open for further replies.

mattygriff

Programmer
May 14, 2001
350
GB
Please look at the following code :
Code:
<%
if intWickets = 0 then
decBowlAv = 0
else
[COLOR=red]decBowlAv = formatnumber((intRuns/intWickets),2)[/color]
end if
response.write decBowlAv
%>

</td>
<td width="50"><h6>
<%
intBallsBowled = (int(decOvers)*6) + intTotBalls
if intBallsBowled = 0 then 
decStrikeRate = 0
else
[COLOR=red]decStrikeRate = formatnumber((intBallsBowled/intWickets),2)[/color]
end if
				
response.write decStrikeRate
%>
I have highlighted two calculations in red. The first one works OK but the second returns a "division by zero" error.

How can this be when they both use the same denominator???
 
Yes they use the same denominator but the 1st one only runs when intWickets doesnt equal 0. The 2nd one will execute if intWickets equals 0. Maybe you should put the same conditional code in the 2nd one that you have in the 1st.


Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
You're getting this error because intWickets = 0.

if intBallsBowled = 0 then
decStrikeRate = 0
else
If intWickets > 0 Then
decStrikeRate = formatnumb((intBallsBowled/intWickets),2)
End If
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top