Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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
 
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! :)

 
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.
 
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......




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





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