For C++, you can try:
std::locale get_numpunct_locale(std::locale locale = std::locale(""))
{
#if defined(_MSC_VER) && defined(_ADDFAC) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 403)
// Workaround for older implementations
std::_ADDFAC(locale, new std::numpunct());
return locale;
#else
return std::locale(locale, new std::numpunct());
#endif
}
template
std::string nformat(T value)
{
std::ostringstream ss;
ss.imbue(get_numpunct_locale());
ss << value;
return ss.str();
}