Format double output, 2 decimal positions

I need output to be formatted to only contain 2 decimal positions.
I will include the output section of my code below:

1
2
3
4
5
6
cout << "Subtotal: " << subTot<< endl; //Outputs Subtotal
tax = preTax * 0.05;  //Calculates tax as 5% of the subtotal
cout << "Tax is: " << tax << endl; //Outputs tax
postTax = preTax + tax; //Adds tax to subtotal for final total
cout << "Total Amount Due: " << totalDue << endl; //outputs final total
}


I need preTax, tax, and totalDue to be formatted to only 2 decimal positions.
You will be wanting to use setprecision() , and to #include <iomanip> .

You can read about it here http://www.cplusplus.com/reference/iomanip/setprecision/
That seems to be just what I'm looking for I think, however there's one thing this doesn't do that I'm looking for.

Is there a way I can FORCE 2 decimal places regardless of rounding? (Such as having it show 1.50 instead of 1.5)?
Topic archived. No new replies allowed.