Why pow(10,5) = 9,999 in C++
问题 Recently i write a block of code: const int sections = 10; for(int t= 0; t < 5; t++){ int i = pow(sections, 5- t -1); cout << i << endl; } And the result is wrong: 9999 1000 99 10 1 If i using just this code: for(int t = 0; t < 5; t++){ cout << pow(sections,5-t-1) << endl; } The problem doesn\'t occur anymore: 10000 1000 100 10 1 Does anyone give me an explaination? thanks you very much! 回答1: Due to the representation of floating point values pow(10.0, 5) could be 9999.9999999 or something