How can I divide two integers to get a double?

后端 未结 5 936
谎友^
谎友^ 2020-11-22 08:39

How do I divide two integers to get a double?

5条回答
  •  -上瘾入骨i
    2020-11-22 09:09

    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

提交回复
热议问题