Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output in Dollar Format

Status
Not open for further replies.

hawaiian1975

Programmer
Nov 7, 2003
26
US
Ok, I made a currency conversion program, however how do I make it so that the output is in dollar format?

Any help would be greatly appreciated.
 
What do you mean, can't you just cout a $ before you cout the number?
 
Well, I got that, however the output is $43.435 I want the output to be $43.43
 
My program is somewhat complete, except I am having trouble formatting the output to show dollar amount with 2 decimal places.

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

void main()
{
// variable declarations
double JPY_Rate = 107.9300 * 1.00;
double EUR_Rate = 0.7954 * 1.00; // Euro
double CAD_Rate = 1.2542 * 1.00; // Canada Dollars
double GBP_Rate = 0.5482 * 1.00; // United Kingdom
double AUD_Rate = 1.3104 * 1.00; // Australia Dollar

// Display Title
cout << "\tCurrency Conversion" << endl;
cout << "\t-------------------" << endl;
cout << "\t1. Japanese Yen: $" << JPY_Rate << endl;
cout << "\t2. Euro: $" << EUR_Rate << endl;
cout << "\t3. Canada Dollars: $" << CAD_Rate << endl;
cout << "\t4. UK Pounds: $" << GBP_Rate << endl;
cout << "\t5. Australian Dollars: $" << AUD_Rate << endl << endl;

cout << "\tPress any key to exit..." << endl;
getchar();

}
 
Just do this before cout-ing the value.

cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);

You'll need to #include <iomanip>, <iostream>, and <cstdio> and get rid of your non-standard includes. The standard library files do not have .h, and the .h files do not exist in the newer versions of Visual Studio. Also don't forget to put "using namespace std;" or put std:: before every cout and every STL function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top