netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] ip-link: in human readable output use dynamic precision length
@ 2014-11-04  9:39 Christian Hesse
  2014-11-04 10:44 ` Christian Hesse
  0 siblings, 1 reply; 7+ messages in thread
From: Christian Hesse @ 2014-11-04  9:39 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Christian Hesse

Now that we use floating point numbers for human readable output we can
calculate precision length on the fly.
---
 ip/ipaddress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index e240bb5..0ddcb0d 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -343,8 +343,8 @@ static void print_num(FILE *fp, unsigned width, uint64_t count)
 		++prefix;
 	}
 
-	snprintf(buf, sizeof(buf), "%.1f%c%s", (double) count / powi, 
-		 *prefix, use_iec ? "i" : "");
+	snprintf(buf, sizeof(buf), "%.*f%c%s", 3 - snprintf(NULL, 0, "%"PRIu64, count / powi),
+		(double) count / powi, *prefix, use_iec ? "i" : "");
 
 	fprintf(fp, "%-*s ", width, buf);
 }
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-05  9:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-04  9:39 [PATCH 1/1] ip-link: in human readable output use dynamic precision length Christian Hesse
2014-11-04 10:44 ` Christian Hesse
2014-11-04 10:50   ` [PATCH v2 " Christian Hesse
2014-11-04 11:06     ` David Laight
2014-11-04 21:10       ` Christian Hesse
2014-11-04 21:17         ` [PATCH v3 " Christian Hesse
2014-11-05  9:30         ` [PATCH v2 " David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).