abc. txt has the following tab delimited values

100 81.7 2000

float tempFloat1;
float tempFloat2;
float tempFloat3;
float tempFloat4;
float tempFloat5;

ifstream inFile ("abc.txt", ios::in);
inFile >> tempFloat1; // debugger - 100
inFile >> tempFloat2; // debugger - 81.699995 WTF1???
inFile >> tempFloat3; // debugger - 100
//old school work around
tempFloat4 = floor(10.*tempFloat2); // debugger shows - 817
tempFloat5 = tempFloat4/10.);// debugger - 81.699995 WTF2???

many floating point values can not be represented exactly in memory due to the way they are stored. For a complete explanation read this wiki article which will probably tell you a lot more than you dared to know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.