C# simple divide problem

前端 未结 9 1014
感动是毒
感动是毒 2020-12-11 01:40

I have this:

 double result = 60 / 23;

In my program, the result is 2, but correct is 2,608695652173913. Where is problem?

9条回答
  •  粉色の甜心
    2020-12-11 01:53

    Haven't used C# for a while, but you are dividing two integers, which as far as I remember makes the result an integer as well.

    You can force your number literals to be doubles by adding the letter "d", likes this:

    double result = 60d / 23d;
    

提交回复
热议问题