The significant digits is 2.
Why the output of
cout << setprecision(2) << 0.999 << endl;`
is 1
instead of 1.0
?
The significant digits is 2.
Why the output of
cout << setprecision(2) << 0.999 << endl;`
is 1
instead of 1.0
?
The default formatting does not print trailing zeros; you need to set the floating point formatting to fixed
, see also this reference. So what you need is
cout << setprecision(2) << fixed << 0.999 << endl;
Note also that setprecision refers to the decimal digits, so for 1.0 you would need setprecision(1)