Use money_put to output monetary values. - C++ Internationalization

C++ examples for Internationalization:Money

Description

Use money_put to output monetary values.

Demo Code

#include <iostream>
#include <locale>
using namespace std;
int main()//from w w w.  ja  va  2  s .  co  m
{
   double balance = 1234.87;
   locale usloc("English_US");
   locale gloc("German_Germany");
   // Set showbase flag so that currency symbol is displayed.
   cout << showbase;
   cout << "Money format for US dollars:\n";
   cout.imbue(usloc);
   const money_put<char> &us_mon = use_facet<money_put<char> >(cout.getloc());
   us_mon.put(cout, false, cout, ' ', "123456");
   cout << endl;
   us_mon.put(cout, true, cout, ' ', -299);
   cout << endl;
   us_mon.put(cout, false, cout, ' ', balance * 100);
   cout << "\n\n";
   cout << "Now show money in international German format:\n";
   cout.imbue(gloc);
   const money_put<char> &g_mon = use_facet<money_put<char> >(cout.getloc());
   g_mon.put(cout, true, cout, ' ', 123456);
   cout << endl;
   g_mon.put(cout, true, cout, ' ', -299);
   cout << endl;
   g_mon.put(cout, true, cout, ' ', balance * 100);
   return 0;
}

Result


Related Tutorials