convert double to integer

vb2005

i finally decided to turn option strict on, and i get a bunch of implicit conversion warnings. what is the best way to convert a Double to an Integer, without using microsoft.visualbasic namespace?
LVL 13
newyuppieAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Ravi SinghConnect With a Mentor Senior Software EngineerCommented:
You could use the Convert class:

        Dim dNum As Double = 10.4
        Dim iNum As Integer = Convert.ToInt32(dNum)
0
 
newyuppieAuthor Commented:
perfect, so that would also truncate the decimals right? no need for convert.toint32(math.truncate(dnum))?
0
 
Ravi SinghSenior Software EngineerCommented:
Hi,

Convert.ToInt32 will round up from above .5, if you only want the integral part of the number then you'll have to call the truncate method.

0
 
newyuppieAuthor Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.