#include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(17); double d = 0.1; cout << d << endl; return 0; }
a) 0.11
b) 0.10000000000000001
c) 0.100001
d) compile time error
#include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(17); double d = 0.1; cout << d << endl; return 0; }
a) 0.11
b) 0.10000000000000001
c) 0.100001
d) compile time error
You must be logged in to post a comment.
b
Explanation: The double had to truncate the approximation due to its limited memory, which resulted in a number that is not exactly 0.1.
Output:
$ g++ float2.out
$ a.out
0.10000000000000001