Divide two integers in .NET
March 26th, 2009 . by Daniel HölblingOk, this is really simple, but it just has cost me 15 minutes because I ignored a compiler warning:
double result = myInt1/myInt2;
The compiler will underline that there is a possible loss in fraction, but I ignored it while not seeing anything wrong with the code at all.
Whatever values I calculated, the result was always an integer. Turns out, dividing two integers will also create an integer instead of a double (so I got weird results like 31/10 = 3 ).
To bypass this, you need to promote at least one of your integers to a double so a double divide will occur:
double result = (double)myInt1 / myInt2;
Hope this helps, took me far too long to figure out.



tz… Anfänger-Fehler ;p
Mark S. is definitely on the right track. If you want to get a professional looking email address, Id recommend buying your name domain name, like or
Gucci sweaters
If its common it might be difficult to get, however, be creative and you can usually find something.
Mark S. is definitely on the right track. If you want to get a professional looking email address, Id recommend buying your name domain name, like or
Jordan OL School
If its common it might be difficult to get, however, be creative and you can usually find something.