projects
/
platform
/
upstream
/
json-c.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
4014fe8
)
Save space, drop unuseful trailing zeroes
author
Remi Collet
<fedora@famillecollet.com>
Thu, 13 Dec 2012 10:22:31 +0000
(11:22 +0100)
committer
Remi Collet
<fedora@famillecollet.com>
Thu, 13 Dec 2012 10:22:31 +0000
(11:22 +0100)
json_object.c
patch
|
blob
|
history
diff --git
a/json_object.c
b/json_object.c
index
eeba91b
..
b078017
100644
(file)
--- a/
json_object.c
+++ b/
json_object.c
@@
-552,13
+552,25
@@
static int json_object_double_to_json_string(struct json_object* jso,
int level,
int flags)
{
- char buf[128], *p;
+ char buf[128], *p
, *q
;
int size;
size = snprintf(buf, 128, "%f", jso->o.c_double);
p = strchr(buf, ',');
if (p) {
*p = '.';
+ } else {
+ p = strchr(buf, '.');
+ }
+ if (p) {
+ /* last useful digit, always keep 1 zero */
+ p++;
+ for (q=p ; *q ; q++) {
+ if (*q!='0') p=q;
+ }
+ /* drop trailing zeroes */
+ *(++p) = 0;
+ size = p-buf;
}
printbuf_memappend(pb, buf, size);
return size;