Skip to content

Commit

Permalink
fixed float serialization (#81 and #80)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jun 4, 2015
1 parent 266399d commit b8d05f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,11 +2284,7 @@ class basic_json
{
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
using std::snprintf;
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();
o << std::setprecision(15) << m_value.number_float;
return;
}

Expand Down
6 changes: 1 addition & 5 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,11 +2284,7 @@ class basic_json
{
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
using std::snprintf;
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();
o << std::setprecision(15) << m_value.number_float;
return;
}

Expand Down

0 comments on commit b8d05f7

Please sign in to comment.