c - C 中括号内的 double

标签 c floating-point double precision

使用替身,我可以设置

double x = 216/22            //Output's 9.818181...

但是,当我尝试时:

double x = (216/22)          //Outputs 9.00000...
double x = ((double)216/22)  //Outputs 9.0000...
double x = (216/(double)22)  //Outputs 9.818181...

为什么 (216/22) 返回 9 而不是 9.8181...?

最佳答案

Why does (216/22) return 9 and not 9.8181...?

因为 216 和 22 都是 int - 并且结果是一个 int。

(216.0/22) 将按预期返回双倍。

关于c - C 中括号内的 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005498/

相关文章:

ios - Swift - 将数组中的值转换为 double 或 float

c++ - 如何查找输入的 double 是否是 0.05 的倍数

c - 为什么需要 '-lpthread' ?

c++ - float 和双重比较最有效的方法是什么?

.net - 通过 float 或decimal 调用参数为 double 的重载函数

python - Python 和一般情况下的浮点相等性

c# - 将 Math.Round 结果转换为 float 是否安全?

c - 将文件作为命令行参数传递

c - 从 GDB 获取堆栈跟踪

Curl 不会在 HTTP POST 请求中发送整个表单数据