]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
feat(output): show loss with two decimals 645/head
authorDarafei Praliaskouski <me@komzpa.net>
Fri, 8 May 2026 14:52:22 +0000 (18:52 +0400)
committerDarafei Praliaskouski <me@komzpa.net>
Mon, 25 May 2026 11:02:56 +0000 (15:02 +0400)
test/cmdparse.py
ui/gtk.c
ui/mtr.c

index 4f5d64cc13e5c8c3291eae5734571361c5f59c8c..f344eafd891f7af55004ebbca510be674945f1c1 100755 (executable)
@@ -81,6 +81,22 @@ class TestMtrCommandParse(unittest.TestCase):
         self.assertIn('port number specified (-P)', reply.stderr)
         self.assertIn('protocol is ICMP', reply.stderr)
 
+    def test_report_loss_uses_two_decimal_places(self):
+        'Test report mode preserves fine-grained loss percentage precision.'
+
+        reply = self.run_mtr(
+            '--report',
+            '--report-cycles',
+            '1',
+            '--no-dns',
+            '127.0.0.1',
+        )
+
+        self.assertEqual(reply.returncode, 0)
+        self.assertEqual(reply.stderr, '')
+        self.assertIn('Loss%', reply.stdout)
+        self.assertIn('0.00%', reply.stdout)
+
     def test_port_with_tcp_succeeds_flag(self):
         'Test that specifying -P with -T (TCP) succeeds.'
 
index a997a33eac6ecc95b77aea8520e85401f48f3203..d1315fe1600bcb51f7ea1fa7df7c0b5fe9acc9c1 100644 (file)
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -373,7 +373,7 @@ static void percent_formatter(
     gfloat f;
     gchar text[64];
     gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1);
-    snprintf(text, sizeof(text), "%.1f%%", f);
+    snprintf(text, sizeof(text), "%.2f%%", f);
     g_object_set(cell, "text", text, NULL);
 }
 
index f3be331e4c9ab820e8441f2fd5564a28b22481ab..98977f6c5cc9531a89cdc805e95d4822617f2b4b 100644 (file)
--- a/ui/mtr.c
+++ b/ui/mtr.c
@@ -69,7 +69,7 @@ char *myname;
 const struct fields data_fields[MAXFLD] = {
     /* key, Remark, Header, Format, Width, CallBackFunc */
     {' ', "<sp>: Space between fields", " ", " ", 1, &net_drop},
-    {'L', "L: Loss Ratio", "Loss%", " %4.1f%%", 6, &net_loss},
+    {'L', "L: Loss Ratio", "Loss%", " %6.2f%%", 8, &net_loss},
     {'D', "D: Dropped Packets", "Drop", " %4d", 5, &net_drop},
     {'R', "R: Received Packets", "Rcv", " %5d", 6, &net_returned},
     {'S', "S: Sent Packets", "Snt", " %5d", 6, &net_xmit},