mirror of
https://github.com/json-c/json-c.git
synced 2026-11-09 23:40:14 +08:00
keep the exponent when trimming zeroes with JSON_C_TO_STRING_NOZERO
This commit is contained in:
1 parent
cdd8db0530
commit
7f4196213a
3 files changed
+22
-5
No files matched your search
+8
-5
@@ -1328,15 +1328,18 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
|
||||
{
|
||||
/* last useful digit, always keep 1 zero */
|
||||
p++;
|
||||
for (q = p; *q; q++)
|
||||
for (q = p; is_plain_digit(*q); q++)
|
||||
{
|
||||
if (*q != '0')
|
||||
p = q;
|
||||
}
|
||||
/* drop trailing zeroes */
|
||||
if (*p != 0)
|
||||
*(++p) = 0;
|
||||
size = p - buf;
|
||||
/* drop trailing zeroes, keeping any exponent after them */
|
||||
if (is_plain_digit(*p))
|
||||
{
|
||||
p++;
|
||||
memmove(p, q, strlen(q) + 1);
|
||||
}
|
||||
size = (int)strlen(buf);
|
||||
}
|
||||
}
|
||||
// although unlikely, snprintf can fail
|
||||
|
||||
Reference in new issue
Block a user