Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does \ perform integer division in VB?

In VB.NET even if both the operands are integer, the / operator will cause the value to be floating point (if the result is non integer).

So I tried with the \ operator which yields integer value irrespective of the operands.
So I thought \ is integer division.

2.5 \ 3 results in 0.

Now I tried 1.5 \ 2. I expected it to be 0 but it resulted in a 1.
Now, is it a bug or a correct result?
What the \ operator actually is?

If it's a bug it exists right through VB6.

like image 257
dotNETbeginner Avatar asked Aug 26 '11 05:08

dotNETbeginner


1 Answers

If you use \ on non-integers, you first convert them to integers, which causes rounding: the equivalent of CLng(1.5) \ 2, which is 2 \ 2 or 1.

If you use Option Strict On then you will see this taking place.

like image 124
user541686 Avatar answered Oct 13 '22 21:10

user541686