Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 4th, 2007, 04:46 AM
Authorized User
 
Join Date: Sep 2004
Location: Sydney, NSW, Australia.
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old August 4th, 2007, 05:06 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

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
Reply With Quote
  #3 (permalink)  
Old August 4th, 2007, 05:51 AM
Authorized User
 
Join Date: Sep 2004
Location: Sydney, NSW, Australia.
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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! :)

Reply With Quote
  #4 (permalink)  
Old August 4th, 2007, 05:53 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

You are most welcome.
Reply With Quote
  #5 (permalink)  
Old August 5th, 2007, 06:07 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: Bangalore, Karnataka, India.
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

thanks......
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a NaN in VBA? rahzan Access VBA 11 March 6th, 2016 08:40 AM
NaN elayaraja.s XSLT 2 September 9th, 2008 04:10 AM
Formatting NaN in a matrix gidsy BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 May 8th, 2007 10:50 AM
Actionscript NaN brainchild Flash (all versions) 1 March 21st, 2007 07:29 AM
format-number NaN rbdave XSLT 1 October 23rd, 2003 06:48 AM



All times are GMT -4. The time now is 09:45 PM.


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