How can I improve formatting number with commas performance?
问题 I'm using the following method to format a number with commas: template<class T> static std::string FormatNumberWithCommas(T value, int numberOfDecimalPlaces = 0) { std::stringstream ss; ss.imbue(std::locale("")); ss.precision(numberOfDecimalPlaces); ss << std::fixed << value; return ss.str(); } Profiling has show this method to take a significant amount of time relative to other code. Specifically the profiler has identified the line: ss.imbue(std::locale("")); And within that I believe it