Commit b8d05f72 authored by Niels's avatar Niels

fixed float serialization (#81 and #80)

parent 266399d8
...@@ -2284,11 +2284,7 @@ class basic_json ...@@ -2284,11 +2284,7 @@ class basic_json
{ {
// 15 digits of precision allows round-trip IEEE 754 // 15 digits of precision allows round-trip IEEE 754
// string->double->string // string->double->string
using std::snprintf; o << std::setprecision(15) << m_value.number_float;
const auto sz = static_cast<unsigned int>(snprintf(nullptr, 0, "%.15g", m_value.number_float));
std::vector<typename string_t::value_type> buf(sz + 1);
snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
o << buf.data();
return; return;
} }
......
...@@ -2284,11 +2284,7 @@ class basic_json ...@@ -2284,11 +2284,7 @@ class basic_json
{ {
// 15 digits of precision allows round-trip IEEE 754 // 15 digits of precision allows round-trip IEEE 754
// string->double->string // string->double->string
using std::snprintf; o << std::setprecision(15) << m_value.number_float;
const auto sz = static_cast<unsigned int>(snprintf(nullptr, 0, "%.15g", m_value.number_float));
std::vector<typename string_t::value_type> buf(sz + 1);
snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
o << buf.data();
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment