I have a quick question regarding precision printing output to cout. I need a way to print a MINIMUM number of decimal place digits to cout and also possibly have a maximum number of decimal places printed. Also, I need a way to "undo" if you will a call to setprecision.
So here is my problem, if a number is an integer, such as 2, I want to be able to print it out as 2.0. But the problem I am having is that if I do:
cout << fixed << setprecision(1) << number;
If I do this, setprecision will be set to 1 for the rest of my program, but I do not want that. So in theory I want to be able to do these operations in a row:
Print 2 as 2.0 (can do with a fixed precision of 1)
Print 3.75 as 3.75 (can change fixed precision to 2 for this but don't want a precision limit)
Print 3.5 as 3.5 (do not want a precision limit here)
So my main problem is, I want to be able to reset a call to setprecision after I use it so that only the precision of the current call is affected. I have tried the following commands to reset the flags:
But these only seem to affect whether the flag is set to fixed or scientific and it does not undo the call to setprecision.
I guess my main question is, is it possible to undo a call to setprecision and reset it to the default value it was at? If so what call would that be?
Or, is it possible do a setprecision call where I state the minimum number of decimal places to print as well as the maximum number of decimal places to print?
Thank you for any help, if it is somewhat confusing just ask and I can clarify some more.