• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

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?
0
newyuppie
Asked:
newyuppie
  • 2
  • 2
1 Solution
 
Ravi SinghSenior 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now