The following snippet outputs 0.29847 when I would have expected 0.29848:
double f = 0.298475;
cout << setprecision(5) << f << endl;
For other examples, however, I observe rounding:
double f = 0.123459;
cout << setprecision(5) << f << endl;
outputs: 0.12346
and
double f = 0.123454;
cout << setprecision(5) << f << endl;
outputs: 0.12345
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…