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) ?
Printable View
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) ?
Like this?
- petterCode:float f = 100.3f;
printf("%.2f", f);
no i don't think so... the variables i want formatted aren't predefined, they are calculated by the application.
The answer is still valid,
Puts your floating point number into the output buffer as a string of the number to two decimal places.Code:printf("%.2f", f);
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
resulting in 342.32 being displayedCode:double dollar = 342.3287
cout << setprecision(2) << fixed << dollar << endl;
but thanks, both methods work great!