与Why does this double to int conversion not work?有关的问题
#include <iostream>
int main()
{
double x = 4.10;
double j = x * 100;
int k = (int) j;
std::cout << k;
}
Output: 409
但是用10代替100:
#include <iostream>
int main()
{
double x = 4.10;
double j = x * 10;
int k = (int) j;
std::cout << k;
}
Output: 41
由于实际存储的值大约为4.099999 ...由于截断,我希望得到40,而不是确切的值41。
发生了什么事?