-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not use std::to_string #51
Comments
Thanks for the hint. I'll check. |
Hi @krisztiantobias, the current code does not use case (value_t::number_float):
{
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
std::vector<char> buf(sz + 1);
std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
return string_t(buf.data());
} Do you see the same issue there? If so, wouldn't prepending std::locale::global(std::locale::classic()); fix the issue? |
It's fix that, but very ugly I think. In our code I fix that with this: Before dump: template<typename CharT>
class DecimalSeparator : public std::numpunct<CharT>
{
public:
DecimalSeparator(CharT Separator)
: m_Separator(Separator)
{}
protected:
CharT do_decimal_point()const
{
return m_Separator;
}
private:
CharT m_Separator;
}; And in dump: case (value_t::number_float):
{
std::stringstream ss;
ss.imbue(std::locale(std::locale(), new DecimalSeparator<char>('.')));
ss << m_value.number_float;
return ss.str();
} |
This is simply wrong:
The to_string use std::locale what can change the point to comma (happened with us, because in QT the QApplication create change this) what is not good for json. You have to use always point instead of comma (json rpc standard)
The text was updated successfully, but these errors were encountered: