使用替身,我可以设置
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/