C# simple divide problem

前端 未结 9 1017
感动是毒
感动是毒 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:59

    It is best practice to correctly decorate numerals for their appropriate type. This avoids not only the bug you are experiencing, but makes the code more readable and maintainable.

    double x = 100d;
    single x = 100f;
    decimal x = 100m;
    

提交回复
热议问题