How to divide the integer value

Gopal picture Gopal · Oct 17, 2012 · Viewed 8.7k times · Source

I want to perform integer division in VB.NET, i.e. only keep the whole part of division result.

Dim a, b, c as int32
a = 3500
b = 1200
c = a/b

This example outputs 3.

How do I make it return 2 instead?

Answer

Mark Hall picture Mark Hall · Oct 17, 2012

Since this is Visual Basic you have 2 division operators / which is for Standard division and \ which is used for integer division, which returns the "integer quotient of the two operands, with the remainder discarded" which sounds like what you want.

results:

a/b = 3
a\b = 2