about summary refs log tree commit diff
path: root/cli
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-03-20 21:45:02 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-03-20 21:45:02 +0000
commit4e6f095c4127cb95841defd33ee6f8729f7f4865 (patch)
tree8f1ba401bb623c04b3bf5f8f380f6869f0c85501 /cli
parentdb497638492bba06ce2a27f39bf72c6acaa395dc (diff)
downloadbtpd-4e6f095c4127cb95841defd33ee6f8729f7f4865.tar.gz
btpd-4e6f095c4127cb95841defd33ee6f8729f7f4865.zip
Cut off decimals after the first tenth percent so printf doesn't round
the percentage upwards. Ie. Display 99.9%, not 100.0%, even if we have
99.98% of the content.

Diffstat (limited to 'cli')
-rw-r--r--cli/btcli.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/cli/btcli.c b/cli/btcli.c
index 00c747f..95ae487 100644
--- a/cli/btcli.c
+++ b/cli/btcli.c
@@ -7,6 +7,7 @@
 #include <getopt.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -64,13 +65,13 @@ print_stat(struct tpstat *ts)
 {
     printf("%c %5.1f%% %6.1fM %7.2fkB/s %6.1fM %7.2fkB/s %4u %5.1f%%",
         state_char(ts),
-        100.0 * ts->content_got / ts->content_size,
+        floor(1000.0 * ts->content_got / ts->content_size) / 10,
         (double)ts->downloaded / (1 << 20),
         (double)ts->rate_down / (20 << 10),
         (double)ts->uploaded / (1 << 20),
         (double)ts->rate_up / (20 << 10),
         ts->peers,
-        100.0 * ts->pieces_seen / ts->torrent_pieces);
+        floor(1000.0 * ts->pieces_seen / ts->torrent_pieces) / 10);
     if (ts->tr_errors > 0)
         printf(" E%u", ts->tr_errors);
     printf("\n");