473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dividing\Remain der

gh
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
Nov 17 '05 #1
3 16054
> 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#?


The % operator.

--

www.midnightbeach.com
Nov 17 '05 #2
On Sun, 22 May 2005 15:53:19 -0500, gh <gh@at.ne> wrote:
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


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
Nov 17 '05 #3
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:eg******** ******@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
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.