Re:Curious lack of sprintf scaling
by jcelerier on Saturday February 26, 2022 @02:19AM
(#30475790)
C++ has thankfully locale- independent functions now, std::from_chars, std::to_chars.. but it took way too many years
[ Parent
| on HN ]
I am very curious to know why you guys are forgetting std::to_string. It is available since c++11. This and then str.c_ctr() should make the trick in most cases.
to_string is just a wrapper around sprintf... here's the (de-__uglyfied) code on libstdc++:
inline string
to_string(float val)
{
const int n = gnu_cxx::numeric_traits<float>::max_exponent10 + 20;
return gnu_cxx::to_xstring<string>(&std::vsnprintf, n, "%f", val);
}
it will be worse in pretty much every metric than fmt::format("{}", val);
Re:Curious lack of sprintf scaling
by formerly_proven on Saturday February 26, 2022 @07:54AM
(#30477158)
to_string uses the locale.