Commit 237c1849 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov

ioping: print at least three decimal digits

This prints two digits after decimal point if value lower than ten and
dosn't print decimal point at all if unit exactly fits to the value.
Signed-off-by: default avatarKonstantin Khlebnikov <koct9i@gmail.com>
parent 25446637
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <inttypes.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
...@@ -353,12 +352,19 @@ long long parse_time(const char *str) ...@@ -353,12 +352,19 @@ long long parse_time(const char *str)
void print_suffix(int64_t val, struct suffix *sfx) void print_suffix(int64_t val, struct suffix *sfx)
{ {
int precision;
while (val < sfx->mul && sfx->mul > 1) while (val < sfx->mul && sfx->mul > 1)
sfx++; sfx++;
if (sfx->mul == 1)
printf("%" PRId64, val); if (val % sfx->mul == 0)
precision = 0;
else if (val >= sfx->mul * 10)
precision = 1;
else else
printf("%.1f", val * 1.0 / sfx->mul); precision = 2;
printf("%.*f", precision, val * 1.0 / sfx->mul);
if (*sfx->txt) if (*sfx->txt)
printf(" %s", sfx->txt); printf(" %s", sfx->txt);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment