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

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

    In my case nothing worked above.

    what I want to do is divide 278 by 575 and multiply by 100 to find percentage.

    double p = (double)((PeopleCount * 1.0 / AllPeopleCount * 1.0) * 100.0);
    

    %: 48,3478260869565 --> 278 / 575 ---> 0 %: 51,6521739130435 --> 297 / 575 ---> 0

    if I multiply the PeopleCount by 1.0 it makes it decimal and division will be 48.34... also multiply by 100.0 not 100.

提交回复
热议问题