Skip to content

Commit 4a9d77b

Browse files
Fix issue open-source-parsers#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.
1 parent 56efb6b commit 4a9d77b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p
150150
// concepts of reals and integers.
151151
if (isfinite(value)) {
152152
len = snprintf(buffer, sizeof(buffer), formatString, value);
153-
153+
fixNumericLocale(buffer, buffer + len);
154+
154155
// try to ensure we preserve the fact that this was given to us as a double on input
155156
if (!strstr(buffer, ".") && !strstr(buffer, "e")) {
156157
strcat(buffer, ".0");
@@ -165,10 +166,8 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p
165166
} else {
166167
len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999");
167168
}
168-
// For those, we do not need to call fixNumLoc, but it is fast.
169169
}
170170
assert(len >= 0);
171-
fixNumericLocale(buffer, buffer + len);
172171
return buffer;
173172
}
174173
}

0 commit comments

Comments
 (0)