From 4a9d77bcf7216592ebe8190f0653ecf0ebdbdc00 Mon Sep 17 00:00:00 2001 From: Bernhard Hartleb Date: Thu, 22 Jun 2017 22:46:16 +0200 Subject: [PATCH] Fix issue #567 in writing real values in different locales The output of snprintf might produce ',' separators for decimal places if certain locales are set. This commit moves the converversion from ',' to '.' to correct place. Otherwise an additional ".0" might be appended. --- src/lib_json/json_writer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 2ab16ac..5fc4bf0 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -150,7 +150,8 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p // concepts of reals and integers. if (isfinite(value)) { len = snprintf(buffer, sizeof(buffer), formatString, value); - + fixNumericLocale(buffer, buffer + len); + // try to ensure we preserve the fact that this was given to us as a double on input if (!strstr(buffer, ".") && !strstr(buffer, "e")) { strcat(buffer, ".0"); @@ -165,10 +166,8 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p } else { len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999"); } - // For those, we do not need to call fixNumLoc, but it is fast. } assert(len >= 0); - fixNumericLocale(buffer, buffer + len); return buffer; } }