Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

VS 2010 Integer division by 2

$
0
0
By using a simple loop to keep dividing 10 by 2, I get these results:
5-2-1

Whereas I should get: 5-3-2-1 (for example:5/2 = 2.5 since it is an integer
it must be rounded to 3)

How this happens?
Or how integers division works?

Thank you.



Code:

Dim digit As Integer
 dim result as integer
        Integer.TryParse(txtDigit.Text, digit)
        Do
          result = digit / 2
          digit = result
            txtDisplay.Text += result.ToString & vbNewLine
        Loop Until digit = 1


Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>