|
-
February 15th, 2006, 06:30 PM
#1
Output formatting
Beginner question, how would I format output's to limit decimal places to 2 (0.00), and add 0's when neccisary (1 to 1.00, 1.2 to 1.20) ?
-
February 15th, 2006, 07:36 PM
#2
Re: Output formatting
Like this?
Code:
float f = 100.3f;
printf("%.2f", f);
- petter
-
February 15th, 2006, 09:07 PM
#3
Re: Output formatting
no i don't think so... the variables i want formatted aren't predefined, they are calculated by the application.
-
February 15th, 2006, 10:44 PM
#4
Re: Output formatting
The answer is still valid,
Puts your floating point number into the output buffer as a string of the number to two decimal places.
-
February 18th, 2006, 07:26 PM
#5
Re: Output formatting
Hm, thanks for the help, but couldn't I just use the setprecision manipulator?
like for dollar ammounts i'd have to used fixed along with setprecision in such a manner
Code:
double dollar = 342.3287
cout << setprecision(2) << fixed << dollar << endl;
resulting in 342.32 being displayed
but thanks, both methods work great!
Last edited by 80Degrees; February 18th, 2006 at 10:11 PM.
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
|