<分区>
Possible Duplicate:
Floating point inaccuracy examples
我在 C/C++ 的 WHILE 循环中有以下行:
while(...)
{
x = x + float(0.1); // x is a float type. Is the cast necessary?
}
x 从 0 开始。问题是,在我的第一个循环之后,x = 0.1。这很酷。在我的第二个循环之后,x = 0.2。那真好;那真甜。但是,在我的第三个循环之后,x = 0.3000001。那不行。我希望它的值为 0.3,而不是 0.3000001。可以吗?我循环错了吗?