p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   NaN (http://p2p.wrox.com/showthread.php?t=60809)

spinout August 4th, 2007 04:46 AM

NaN
 
Hello Everyone.

Does anyone know how I can check for NaN? I have this function which works well, except for when Votes and TotalVotes are both equal to 0.

Code:

Public Function CalculatePercentage(ByVal Votes As Integer, ByVal TotalVotes As Integer)
  Dim Calculate
  Calculate = Math.Round(Votes / TotalVotes * 100)
  Calculate = Convert.ToInt32(Calculate)
  Return Calculate
End Function


gaurav_jain2403 August 4th, 2007 05:06 AM

why dont you check the values before performing the divide function.

if (not Votes = 0 and not TotalVotes = 0)
   Calculate = Math.Round(Votes / TotalVotes * 100)

Else describe in more detail what is your problem exactly

spinout August 4th, 2007 05:51 AM

Quote:

quote:Originally posted by gaurav_jain2403
 why dont you check the values before performing the divide function.
Good point!! That works!

It pays to do these things when you're not tired and can actually think straight. :)

Thanks for your help! :)


gaurav_jain2403 August 4th, 2007 05:53 AM

You are most welcome.

MunishBhatia August 5th, 2007 06:07 AM

to put code in try catch block is always a good practice.
you can also use that.

thanks......


All times are GMT -4. The time now is 08:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.