我以前从未真正使用过花车,而我正在从事的当前项目需要它们。我遇到了几年前了解到的奇怪问题,但已经忘记了为什么会发生这种情况。
我乘以或添加浮点数后的结果不是他们应该的。
这是我的代码:
void main ()
{
//Example 1 - ERROR
float a=16937.6;
float b=112918;
float total=b+a;
cout<<total<<endl; //Outputs 129896 - rounds up and loses decimal (129855.6)
//Example 2 - Error
float c=247.82;
float d=9995.2;
float total2=c+d;
cout<<total2<<endl; //Outputs 10243 - loses all decimals (10243.02)
system ("pause");
}