S
Samuel R. Neff
We've been doing a little experimenting and it seems VB.NET doesn't
have a direct equivalent to a C# double to integer cast.
Dim d as Double = 2.5#
Dim i as Integer = CType(d, Integer)
Is decompiled to
double d = 2.5;
int i = (int)Math.Round(d);
and
Dim d as Double = 2.5#
Dim i as Integer = CType(Math.Floor(d),Integer)
Is decompiled to
double d = 2.5;
int i = (int)Math.Round(Math.Floor(d));
So how the heck can you do a straight cast in VB.NET? DirectCast
doesn't work on value types and the CType functions always add a
Math.Round call. CInt(d) gives same results as CType(d, Integer).
The Convert.ToInt32() function also does rounding.
Thanks,
Sam
have a direct equivalent to a C# double to integer cast.
Dim d as Double = 2.5#
Dim i as Integer = CType(d, Integer)
Is decompiled to
double d = 2.5;
int i = (int)Math.Round(d);
and
Dim d as Double = 2.5#
Dim i as Integer = CType(Math.Floor(d),Integer)
Is decompiled to
double d = 2.5;
int i = (int)Math.Round(Math.Floor(d));
So how the heck can you do a straight cast in VB.NET? DirectCast
doesn't work on value types and the CType functions always add a
Math.Round call. CInt(d) gives same results as CType(d, Integer).
The Convert.ToInt32() function also does rounding.
Thanks,
Sam