4
I would like to present values formatted as currency, with thousands and cents separators.
I would like for example, 56000/12
present 4.666,67
. I can present 4,666.67
. Would there be some way to change the .
(point) by ,
(comma)?
If you want, this is the code I use (the first 11 entries are 5000 and the 12th is 1000):
#include <iostream>
#include <iomanip>
#include <locale.h>
using namespace std;
class BRL : public numpunct<char>
{
protected:
virtual char do_thousands_sep() const
{
return ',';
}
virtual std::string do_grouping() const
{
return "\03";
}
};
int menor5000;
float stop,media,mes,tot,var;
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "portuguese");
cout <<"\n\t\tExercício 5\n";
locale br(locale(), new BRL());
cout.imbue(br);
for (menor5000,mes=1,stop=0;stop<12;stop++,mes++)
{
cout<<"Digite o valor da venda no " << mes <<"º mês: ";
cin>>var;
if (var < 5000)
menor5000++;
tot = tot + var;
}
media = tot / 12;
cout<<"\n\nA media de vendas mensais em 2013 é de R$ " << setiosflags (ios::fixed) << setprecision(2) << media << "\n";
cout << "\nForam realizadas " << menor5000 << " vendas menores que R$ 5,000.00.";
return 0;
system ("pause");
}
Does that answer you? http://answall.com/questions/9810/formatr-decimal-com-virgula-e-mile_com-dot
– Maniero