When two variables are declared as integer type and you perform
14/4, you get 4, but when you use integer division, 14\4, you get 3.
I thought when you use integer division it rounds to the closest even number. So 14\4 = 3.5 (4 is the closest even number) should be 4 instead, right?
If the divisor and dividend have the same sign then the result is zero or positive. If the divisor and dividend have opposite signs then the result is zero or negative. If the division is inexact then the quotient is rounded up.
Integer division is carried out using the \ Operator (Visual Basic).
First, set up the long division. Next, ignore the decimal point and divide as you would divide whole numbers. Then, place the decimal point in the quotient directly above the decimal point in the dividend. The answer is 6.9.
In VB.NET, the /
operator is defined to return a floating-point result. It converts the variables to double before performing the division.
This is not the case in the integer division \
where the division is performed without the remainder if the quotient is a decimal (decimals are ignored). For example if the quotient is 3.x
, then x
is ignored
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With