diff options
| author | djcb <djcb@djcbsoftware.nl> | 2015-08-18 16:18:02 +0300 |
|---|---|---|
| committer | Emmanuele Bassi <ebassi@gnome.org> | 2017-03-13 09:20:45 +0000 |
| commit | b9007d48d0a3f3d819d727d825fa589fa9cc9557 (patch) | |
| tree | 032de0364912a52287c26593b50e334ef91e43e7 /json-glib/json-generator.c | |
| parent | 41dbbd6fd7b45c850e2942c2259f2bb23bfe52ef (diff) | |
| download | json-glib-b9007d48d0a3f3d819d727d825fa589fa9cc9557.tar.gz | |
Don't loose decimal in whole-double -> string conversion
When converting json to its string representation, whole-doubles (such
as 1.0) would be converted into strings without decimals ("1"). That can
be inconvenient e.g. when converting from/to GVariants.
To avoid this, append '.0' to the string representation for doubles if
they lost their decimals in the conversion.
Also add / update unit tests for this.
https://bugzilla.gnome.org/show_bug.cgi?id=753763
Diffstat (limited to 'json-glib/json-generator.c')
| -rw-r--r-- | json-glib/json-generator.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c index 42681f6..879f3be 100644 --- a/json-glib/json-generator.c +++ b/json-glib/json-generator.c @@ -342,6 +342,11 @@ dump_value (JsonGenerator *generator, g_string_append (buffer, g_ascii_dtostr (buf, sizeof (buf), json_value_get_double (value))); + /* ensure doubles don't become ints */ + if (g_strstr_len (buf, G_ASCII_DTOSTR_BUF_SIZE, ".") == NULL) + { + g_string_append (buffer, ".0"); + } } break; |
