<分区>
我有一个奇怪的问题。这是我的部分代码:
int temp=1100;
int foo=floor(0.03*temp);
int foo1=0.03*temp;
if(foo-foo1){
cout<<foo<<endl;
cout<<foo1<<endl;
}
如果 temp
的 3% = 整数,则 foo
与 foo1
相差 1。
例如:
1100*0.03=33.
foo
=33
foo1
=32.
另外,如果我这样写:
int foo=floor(0.03*1100);
int foo1=0.03*1100;
不存在这样的问题。
为什么?