用整数分隔一个double [英] Dividing a double with integer
本文介绍了用整数分隔一个double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在用 int
分隔 double
时遇到问题。代码片段是:
double db = 10;
int fac = 100;
double res = db / fac;
res的值是 0.10000000000000001
,而不是 0.10
。
有谁知道这是什么原因?我使用cc来编译代码。
解决方案
您需要阅读经典论文每位计算机科学家应该了解的有关浮点运算的知识。
I am facing an issue while dividing a double
with an int
. Code snippet is :
double db = 10;
int fac = 100;
double res = db / fac;
The value of res is 0.10000000000000001
instead of 0.10
.
Does anyone know what is the reason for this? I am using cc to compile the code.
解决方案
You need to read the classic paper What Every Computer Scientist Should Know About Floating-Point Arithmetic.
这篇关于用整数分隔一个double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文