Also use 'g' specifier instead of 'f' to remove trailing zeros,
and increase precision.
Examples of output :
Before After
8.0Kbps 8Kbps
9.9Mbps 9.92Mbps
55001Mbps 55Gbps
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
{
if (numeric)
sprintf(buf, "%.0f", bw);
- else if (bw > 1000000.)
- sprintf(buf, "%.1fM", bw / 1000000.);
- else if (bw > 1000.)
- sprintf(buf, "%.1fK", bw / 1000.);
+ else if (bw >= 1e9)
+ sprintf(buf, "%.3gG", bw / 1e9);
+ else if (bw >= 1e6)
+ sprintf(buf, "%.3gM", bw / 1e6);
+ else if (bw >= 1e3)
+ sprintf(buf, "%.3gK", bw / 1e3);
else
sprintf(buf, "%g", bw);