]> granicus.if.org Git - json-c/commitdiff
probably worth an option for this
authorRemi Collet <fedora@famillecollet.com>
Thu, 13 Dec 2012 10:46:04 +0000 (11:46 +0100)
committerRemi Collet <fedora@famillecollet.com>
Thu, 13 Dec 2012 10:46:04 +0000 (11:46 +0100)
json_object.c
json_object.h
tests/test_locale.c

index b078017fccc6dd67afcfcf89a87e220c94c2f016..9161b00fa6ed4fb8953d2842f93221319765727f 100644 (file)
@@ -562,7 +562,7 @@ static int json_object_double_to_json_string(struct json_object* jso,
   } else {
     p = strchr(buf, '.');
   }
-  if (p) {
+  if (p && (flags & JSON_C_TO_STRING_NOZERO)) {
     /* last useful digit, always keep 1 zero */
     p++;
     for (q=p ; *q ; q++) {
index 262111262e6d33cd0ad5fa0100e0c5b931f7c436..1f704618de254902e1fe9f5b15976a573df33707 100644 (file)
@@ -42,6 +42,10 @@ extern "C" {
  * for an example of the format.
  */
 #define JSON_C_TO_STRING_PRETTY     (1<<1)
+/**
+ * A flag to drop trailing zero for float values
+ */
+#define JSON_C_TO_STRING_NOZERO     (1<<2)
 
 #undef FALSE
 #define FALSE ((json_bool)0)
index 6926a5d9ce47006c32488aac79a13d8efcaa0ec0..da070cf50c3ae165e5e388c0d16dccd2a6825653 100644 (file)
@@ -23,8 +23,9 @@ int main(int argc, char **argv)
 
        MC_SET_DEBUG(1);
 
-       new_obj = json_tokener_parse("[1.2,3.4,123456.78,5.0]");
+       new_obj = json_tokener_parse("[1.2,3.4,123456.78,5.0,2.3e10]");
        printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
+       printf("new_obj.to_string()=%s\n", json_object_to_json_string_ext(new_obj,JSON_C_TO_STRING_NOZERO));
        json_object_put(new_obj);
 }