Reputation: 45
Format your dollar amount in fixed-point notation, with two decimal places of precision, and be sure the decimal point is always displayed.
cout << "You have made $" << TotalSales <<" dollars from ticket sales!!";
Upvotes: 0
Views: 2290
Reputation: 62063
You could use std::put_money:
std::cout.imbue(std::locale("en_US.utf8"));
std::cout << "You have made "
<< std::showbase << std::put_money(TotalSales * 100.0)
<< " from ticket sales!!";
This will automatically apply decimal and thousands separators. It will also add the currency symbol if you use the showbase
manipulator. The formatting of the currency value will depend on the locale you provide.
Upvotes: 2
Reputation: 91
std::setprecision()
as well as std::fixed
are the functions you want:
std::cout <<std::fixed <<std::setprecision(2) <<"You have made $" <<TotalSales <<" dollars from ticket sales!!";
Upvotes: 1