Why is the answer of this code snippet 400.002 and not just 400?
#include <iostream>
int main(){
using namespace std;
float a = 123.4;
a = (a - int(a))*1000;
cout << a << endl;
return 0;
}
I'm a newbie. Is this due to the accuracy of the float
, or is it due to some other reason? What should I do if I just want to keep into consideration of only one decimal place?