C#简单的除法问题 [英] C# simple divide problem

查看:185
本文介绍了C#简单的除法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的:

 double result = 60 / 23;

在我的计划,结果是2,但正确的是2,608695652173913。在哪里的问题。

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

推荐答案

您可以使用以下任一都将给予 2.60869565217391 的:

You can use any of the following all will give 2.60869565217391:

 double result = 60 / 23d;  
 double result = 60d / 23;  
 double result = 60d/ 23d;  
 double result = 60.0 / 23.0;   



但是

double result = 60 / 23;  //give 2



说明:

如果任何数量的两倍它会给双

编辑:

文档

的表达的评估是根据下面的规则进行的:

The evaluation of the expression is performed according to the following rules:


  • 如果所述浮点之一点类型是double,则表达式的计算结果一倍(或关系或布尔表达式的情况下,布尔)。

  • If one of the floating-point types is double, the expression evaluates to double (or bool in the case of relational or Boolean expressions).

如果没有在表达没有double类型,它计算浮动(或布尔在关系或布尔表达式的情况下)。

If there is no double type in the expression, it evaluates to float (or bool in the case of relational or Boolean expressions).

这篇关于C#简单的除法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆