Home > VB.net > Integer Division in VB.NET

Integer Division in VB.NET

In vb.net , backslash(\) is the integer division and forward-slash(/) is not integer division.
Here is the code

    Sub Main()
        Console.WriteLine("Using backslash(\) ,integer division")
        Console.WriteLine(1 \ 2)
        Console.WriteLine("Using forward-slash(/) ,nomral division")
        Console.WriteLine(1 / 2)
        Console.WriteLine("Press Any key to continue.")
    End Sub

The result will be

Using backslash (\),integer division
Using forward-slash(/) ,nomral division
Press Any key to continue.
Categories: VB.net
  1. Jim
    December 17, 2010 at 8:42 pm

    Great explanation of the / vs \ operator in VB.NET

    I would make a couple of corrections in your code. First, you have the forward slash labeled as integer division. You describe it correctly in description, but have it mismatched in your code.

            Console.WriteLine("Using forward-slash(/), integer division")

    Should be:

            Console.WriteLine("Using forward-slash(/), normal division")

    And the backslash comment should be switched as well to read that it is the “integer division” and not the “normal division”.

    Overall, good stuff.

    • ybbest
      January 9, 2011 at 6:25 am

      Thanks for letting me know the errors and all have been corrected.

  2. EditorAtLarge
    September 2, 2012 at 3:46 am

    You misspelled “normal” after “correcting” your post.

  3. EditorAtLarge
    September 2, 2012 at 3:55 am

    At any rate, what you describe as “normal” division is more correctly termed “floating point division”.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: