I want to format a double variable to have two decimal places no matter what. Is there a way to do this without lengthy code?
Example:
Code:4 -> 4.00
4.4 -> 4.40
4.44 -> 4.44
etc..
Printable View
I want to format a double variable to have two decimal places no matter what. Is there a way to do this without lengthy code?
Example:
Code:4 -> 4.00
4.4 -> 4.40
4.44 -> 4.44
etc..
You can use any of the usual stream manipulators...Code:ostringstream oss;
oss.precision(2); // play with this :D
oss << num;
in standard C - printf("%8.2f",mydouble);
the 8 is the number of positions in front of the decimal point, the 2 is the number after it.
:D
I know this was a few months ago, but thanks for the help.
I don't remember what I went with, but nowadays I use setprecision(2).
Man I really asked some noob questions back in the day. :(