|
-
Apr 18th, 2002, 02:07 PM
#1
Thread Starter
Stuck in the 80s
Format Doubles
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..
-
Apr 18th, 2002, 05:04 PM
#2
Monday Morning Lunatic
Code:
ostringstream oss;
oss.precision(2); // play with this :D
oss << num;
You can use any of the usual stream manipulators...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 18th, 2002, 05:12 PM
#3
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.
-
Oct 25th, 2002, 08:32 AM
#4
Thread Starter
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|