Re:Curious lack of sprintf scaling
by gustavorg on Saturday February 26, 2022 @06:35AM
(#30476784)
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.
[ Parent
| on HN ]
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.