473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dividing\Remainder

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 16037
> 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.DivRem which does
both the division & the remainder in one statement.

Hope this helps
Jay

"gh" <gh@at.ne> wrote in message
news:eg**************@TK2MSFTNGP15.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.