Skip to content

Commit

Permalink
Revert "Merge pull request open-source-parsers#7 from steffen-kiess/f…
Browse files Browse the repository at this point in the history
…ix-locale"

This reverts commit 0db9d6e, reversing
changes made to 06dcb1f.

For discussion, see
  open-source-parsers#9
  open-source-parsers#3
  • Loading branch information
cdunn2001 committed Jul 11, 2014
1 parent 655a9db commit 49c7326
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ std::string valueToString(UInt value) {
#endif // # if defined(JSON_HAS_INT64)

std::string valueToString(double value) {
// We need not request the alternative representation
// that always has a decimal point because JSON doesn't distingish the
// concepts of reals and integers.
std::stringstream str;
// Set locale to "C" to always get a '.' instead of a ','
str.imbue(std::locale::classic());
str.precision(16);
str << value;
return str.str();
// Allocate a buffer that is more than large enough to store the 16 digits of
// precision requested below.
char buffer[32];

// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distingish the
// concepts of reals and integers.
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
// visual studio 2005 to
// avoid warning.
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
#else
snprintf(buffer, sizeof(buffer), "%.16g", value);
#endif

return buffer;
}

std::string valueToString(bool value) { return value ? "true" : "false"; }
Expand Down

0 comments on commit 49c7326

Please sign in to comment.