With the following code:
int ten{ 1 };
double zeroPnine{ 0.9 };
cout << ten - zeroPnine << endl; // 0.1
cout << (ten - zeroPnine) * 10 << endl; // 1
cout << static_cast <int>(ten - zeroPnine) << endl; // 0
cout << static_cast <int>((ten - zeroPnine) * 10 )<< endl; // 1
I am expecting the last line to output 1, but actual output is in actually 0, how come?
Full output:
0.1
1
0
0
0.9is not an integer by the way.0.9is actually0.90000000000000002220446049250313080847263336181640625