How can I divide two integers to get a double?

leora picture leora · Mar 19, 2009 · Viewed 234.6k times · Source

How do I divide two integers to get a double?

Answer

NoahD picture NoahD · Mar 19, 2009

You want to cast the numbers:

double num3 = (double)num1/(double)num2;

Note: If any of the arguments in C# is a double, a double divide is used which results in a double. So, the following would work too:

double num3 = (double)num1/num2;

For more information see:

Dot Net Perls