I am having trouble getting my program to output the correct precision for my doubles. Say I have a
double d;
After running some algorithm, I get d
as my output. I want to set the precision of my d
variable to 4 points of precision after decimal. I should be able to do this like so:
cout << setprecision(4) << d;
The problem is that if I if d
is an integer, then no decimal placed are printed.
For example, if d == 120
, then my program will print 120
. I want it to print 120.0000
instead. How do I get my program to always print 4 decimal places?