Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to divide the integer value

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?

like image 795
Gopal Avatar asked Oct 17 '12 19:10

Gopal


2 Answers

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
like image 167
Mark Hall Avatar answered Nov 11 '22 18:11

Mark Hall


Actual calculation: 3500/1200 = 2.916

You have to use Math.Floor method to roundup the value to 2 as below -

c = Math.Floor(a/b)

More information is available on MSDN - Math.Floor

like image 44
Parag Meshram Avatar answered Nov 11 '22 20:11

Parag Meshram