From cbebc98fa9d7b4f6aec4c7de1ceb8c6f4a8b06e3 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Tue, 24 Jun 2025 19:53:33 +0200 Subject: [PATCH] enh(generic-snmp): new comment --- experimental/src/output/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/experimental/src/output/mod.rs b/experimental/src/output/mod.rs index 9acb65dfd..b51034b5a 100644 --- a/experimental/src/output/mod.rs +++ b/experimental/src/output/mod.rs @@ -185,6 +185,20 @@ impl<'a> OutputFormatter<'a> { std::format!("{}{}", prefix, "blabla") } } + +/// Converts a floating point number to a string with two decimal places, +/// removing trailing zeros and the decimal point if necessary. +/// This is useful for formatting metrics in a more human-readable way. +/// +/// For example: +/// ``` +/// let val = 40.009; +/// let formatted = float_string(&val); +/// // assert_eq!(formatted, "40.01"); +/// let val = 40.0; +/// let formatted = float_string(&val); +/// // assert_eq!(formatted, "40"); +/// ``` pub fn float_string(val: &f64) -> String { let mut s = format!("{:.2}", val); while s.ends_with('0') {