这个怎么理解
#include<iostream>
int main()
{
using namespace std;
float hats=50.25,heads=11.17;
cout.setf(ios_base::fixed,ios_base::floatfield);
cout<<"+="<<hats+heads<<endl;
cout<<"-="<<hats-heads<<endl;
cout<<"*="<<hats*heads<<endl;
cout<<"/="<<hats/heads<<endl;
return 0;
}
结果:
+=61.419998
-=39.080002
*=561.292480
/=4.498657
Press any key to continue
问:
为什么加的结果不是61.42?
减的结果后面怎么多了个2?
[解决办法]
float不精确吧 当float=1;
输出来就可能是大于1或小于1的小数了
[解决办法]