Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to convert a Double to an Integer

Tags:

vb.net

Option Strict was off in my VB app so I have now turned it on. I now have some errors that I am unsure on how to fix:

pnlWait.Top = (Height - pnlWait.Height) / 2

In C# I would just do:

pnlWait.Top = (int)(Height - pnlWait.Height) / 2;

But this doesn't work in VB. I tried Decimal.ToInt32 but then it complains because it is creating a Double with the division and there is no Double.ToInt32. Interger.Parse requires a String, so this can't be any good.

pnlWait.Top = Integer.Parse(((Height - pnlWait.Height) / 2).ToString) 'Yeah, right!

That makes me think CType or DirectCast may be good, but these methods work on many objects so I don't think they could be efficient.

like image 879
John Avatar asked Nov 07 '16 22:11

John


1 Answers

pnlWait.Top = Convert.ToInt32((Me.Height - pnlWait.Height) / 2)
like image 98
Guru Josh Avatar answered Oct 14 '22 05:10

Guru Josh