I have a string that represents a floating point number, like "1000.34". I want to apply some thousand and decimal separator rules to that string so that, for example, it turns into "1,000.34".
I tried to do the following:
ss.imbue(std::locale(ss.getloc(), new mySeparator));
struct mySeparator : std::numpunct<char> {
char do_decimal_point() const {
return '.';
}
char do_thousands_sep() const {
return ',';
}
std::string do_grouping() const {
return "\000"; // Groups of 3
}
};
But this only works when it's a number, not a string:
double number = 1000.34;
ss << number;
How can I do the same when what I have is a string representing the number? Is there an alternative approach?