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

后端 未结 8 867
旧时难觅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:21

    I reckon Decimal.Divide(decimal, decimal) implicitly converts its 2 int arguments to decimals before returning a decimal value (precise) where as 4/5 is treated as integer division and returns 0

提交回复
热议问题