Learning about all functions in <iomanip> and was testing out setprecision() and found that something weird is going on...? I did try to do a search on setprecision() limitatations or similar keywords but can't seem to find the right site... can someone please tell me what's going on?
double a = 0.1, b = 0.2, c = 0.3, d = 0.4, e = 0.5;
double f = 0.6, g = 0.7, h = 0.8, i = 0.9;
cout << setprecision(20) << a << endl;
cout << setprecision(20) << b << endl;
cout << setprecision(20) << c << endl;
cout << setprecision(20) << d << endl;
cout << setprecision(20) << e << endl;
cout << setprecision(20) << f << endl;
cout << setprecision(20) << g << endl;
cout << setprecision(20) << h << endl;
cout << setprecision(20) << i << endl << endl;
float a2 = 0.1, b2 = 0.2, c2 = 0.3, d2 = 0.4, e2 = 0.5;
float f2 = 0.6, g2 = 0.7, h2 = 0.8, i2 = 0.9;
cout << setprecision(20) << a2 << endl;
cout << setprecision(20) << b2 << endl;
cout << setprecision(20) << c2 << endl;
cout << setprecision(20) << d2 << endl;
cout << setprecision(20) << e2 << endl;
cout << setprecision(20) << f2 << endl;
cout << setprecision(20) << g2 << endl;
cout << setprecision(20) << h2 << endl;
cout << setprecision(20) << i2 << endl;
outputs:
0.10000000000000001000
0.20000000000000001000
0.29999999999999999000
0.40000000000000002000
0.50000000000000000000
0.59999999999999998000
0.69999999999999996000
0.80000000000000004000
0.90000000000000002000
0.10000000149011612000
0.20000000298023224000
0.30000001192092896000
0.40000000596046448000
0.50000000000000000000
0.60000002384185791000
0.69999998807907104000
0.80000001192092896000
0.89999997615814209000