MINOR: stats: avoid excessive padding of float values with trailing zeroes
When emitting stats, we don't need to have 6 zeroes after the decimal point
for each value, so let's trim floating point numbers to the longest needed
only.
diff --git a/src/stats.c b/src/stats.c
index 9862fdd..df1e9be 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -374,7 +374,11 @@
case FF_U32: return chunk_appendf(out, "%u", f->u.u32);
case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64);
case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
- case FF_FLT: return chunk_appendf(out, "%f", f->u.flt);
+ case FF_FLT: {
+ size_t prev_data = out->data;
+ out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "%f", f->u.flt));
+ return out->data;
+ }
case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL;
default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
}
@@ -406,7 +410,11 @@
case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32);
case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
- case FF_FLT: return chunk_appendf(out, "flt:%f", f->u.flt);
+ case FF_FLT: {
+ size_t prev_data = out->data;
+ out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "flt:%f", f->u.flt));
+ return out->data;
+ }
case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0));
default: return chunk_appendf(out, "%08x:?", f->type);
}
@@ -448,7 +456,7 @@
(unsigned long long) f->u.u64);
break;
case FF_FLT: type = "\"flt\"";
- snprintf(buf, sizeof(buf), "%f", f->u.flt);
+ flt_trim(buf, 0, snprintf(buf, sizeof(buf), "%f", f->u.flt));
break;
case FF_STR: type = "\"str\"";
value = field_str(f, 0);