Possible Duplicate:
Why does this double to int conversion not work?
Convert double to int lose 1 in c++
#include <iostream>
#include <cmath>
using namespace std;
void main() {
double num = 1234.34;
int numInt = num;
double numAfterPoint = num - numInt; // 0.34
int counter = 1;
double numFloatPower = numAfterPoint;
while (true) {
numFloatPower = numAfterPoint * pow(10.0, counter);
cout << numFloatPower << " > " << (int)numFloatPower << " ";
system("pause");
counter++;
}
}
The current result :
3.4 > 3 Press any key to continue . . .
34 > 33 Press any key to continue . . .
340 > 339 Press any key to continue . . .
3400 > 3399 Press any key to continue . . .
Result Should Be :
3.4 > 3 Press any key to continue . . .
34 > 34 Press any key to continue . . .
340 > 340 Press any key to continue . . .
3400 > 3400 Press any key to continue . . .
etc ...