Why does Decimal.Divide(int, int) work, but not (int / int)?

后端 未结 8 865
旧时难觅i
旧时难觅i 2020-12-08 03:18

How come dividing two 32 bit int numbers as ( int / int ) returns to me 0, but if I use Decimal.Divide() I get the correct answer? I\'m by no means

8条回答
  •  渐次进展
    2020-12-08 04:02

    In the first case, you're doing integer division, so the result is truncated (the decimal part is chopped off) and an integer is returned.

    In the second case, the ints are converted to decimals first, and the result is a decimal. Hence they are not truncated and you get the correct result.

提交回复
热议问题