How to divide the integer value
-
08-07-2021 - |
質問
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?
解決
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
所属していません StackOverflow