Dividing\Remainder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gh

    Dividing\Remainder

    I am dividing var1 by var2 and I want to check and see if there is a
    remainder. How do I do this in C#?

    TIA
  • Jon Shemitz

    #2
    Re: Dividing\Remain der

    > I am dividing var1 by var2 and I want to check and see if there is a[color=blue]
    > remainder. How do I do this in C#?[/color]

    The % operator.

    --

    Midnight Beach is Jon Shemitz, a freelance programmer and author. Jon offers software consulting and contract services, and recently finished his 2nd book - .NET 2.0 for Delphi Programmers.

    Comment

    • rossum

      #3
      Re: Dividing\Remain der

      On Sun, 22 May 2005 15:53:19 -0500, gh <gh@at.ne> wrote:
      [color=blue]
      >I am dividing var1 by var2 and I want to check and see if there is a
      >remainder. How do I do this in C#?
      >
      >TIA[/color]

      Use the modulus (%) operator:

      int var1 = 7;
      int var2 = 4;

      int quotient, remainder;

      quotient = var1 / var2;

      remainder = var1 % var2;


      HTH

      rossum



      The ultimate truth is that there is no ultimate truth

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Dividing\Remain der

        gh,
        In addition to the % operator, you can use System.Math.Div Rem which does
        both the division & the remainder in one statement.

        Hope this helps
        Jay

        "gh" <gh@at.ne> wrote in message
        news:eg9YLBxXFH A.3184@TK2MSFTN GP15.phx.gbl...
        |I am dividing var1 by var2 and I want to check and see if there is a
        | remainder. How do I do this in C#?
        |
        | TIA


        Comment

        Working...