Not quite wqhat I'm looking for: I'm not working with money data, but large integer values. With your solution, there's no way to format integers >999 with punctuation. Am I missing something? ---
// main.cpp
#include <iomanip>
#include <locale>
#include <iostream>
#include <sstream>
using namespace std;
class AndysCommaNumPunct : public numpunct <char>
{
protected:
virtual char do_thousands_sep() const
{
return ',';
}
virtual string do_grouping() const
{
return "\003";
}
};
template <class T>
string AndyFormatWithCommas(T value)
{
stringstream ss;
locale AndyCommaLoc( locale(), new AndysCommaNumPunct() );
ss.imbue(AndyCommaLoc);
ss << setprecision(2) << fixed << value;
return ss.str();
}
int main()
{
int anInt = 31235;
cout << "int: " << AndyFormatWithCommas(anInt) << endl;
float aFloat = 31235.47987;
cout << "float: " << AndyFormatWithCommas(aFloat) << endl;
long aLong = 987654321;
cout << "long: " << AndyFormatWithCommas(aLong) << endl;
double aDouble = 987654321.126456789;
cout << "double: " << AndyFormatWithCommas(aDouble) << endl;
return 0;
}
If you want to filter all of my posts then please read this
article:
<https://support.mozilla.org/en-US/kb/organize-your-messages-using-filters>
In step 7 select "Delete"