mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-28 23:53:36 +00:00
Remove manually the leading zeros in _xs_json_dumps().
This commit is contained in:
parent
a63c9c24c1
commit
6d33117dbe
1 changed files with 14 additions and 1 deletions
15
xs_json.h
15
xs_json.h
|
@ -93,7 +93,20 @@ d_char *_xs_json_dumps(d_char *s, char *data, int level, int indent)
|
||||||
case XSTYPE_NUMBER:
|
case XSTYPE_NUMBER:
|
||||||
{
|
{
|
||||||
char tmp[32];
|
char tmp[32];
|
||||||
snprintf(tmp, sizeof(tmp), "%g", xs_number_get(data));
|
snprintf(tmp, sizeof(tmp), "%.15f", xs_number_get(data));
|
||||||
|
|
||||||
|
/* strip useless zeros */
|
||||||
|
if (strchr(tmp, '.') != NULL) {
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
for (ptr = tmp + strlen(tmp) - 1; *ptr == '0'; ptr--);
|
||||||
|
|
||||||
|
if (*ptr != '.')
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
*ptr = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
s = xs_str_cat(s, tmp);
|
s = xs_str_cat(s, tmp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue