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
@@ -41,6 +41,18 @@ int main(int argc, char **argv)
|
||||
json_object_set_serializer(obj, json_object_double_to_json_string, data, NULL);
|
||||
printf("obj.to_string(reset)=%s\n", json_object_to_json_string_ext(obj, 4));
|
||||
|
||||
json_object_put(obj);
|
||||
/* NOZERO must only trim the fraction, never the exponent */
|
||||
obj = json_object_new_double(1.5e20);
|
||||
printf("obj(1.5e20).to_string(nozero)=%s\n",
|
||||
json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOZERO));
|
||||
json_object_put(obj);
|
||||
obj = json_object_new_double(1.5e20);
|
||||
char data_e[] = "%.3e";
|
||||
json_object_set_serializer(obj, json_object_double_to_json_string, data_e, NULL);
|
||||
printf("obj(1.5e20).to_string(%%.3e,nozero)=%s\n",
|
||||
json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOZERO));
|
||||
|
||||
json_object_put(obj);
|
||||
obj = json_object_new_double(0.52381);
|
||||
|
||||
|
||||
Reference in new issue
Block a user