From 362de7d645dcc50ddef12834ef8a8d328c1ea4ff Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Mon, 26 Aug 2024 09:39:25 +0200 Subject: [PATCH] chore: work towards better number formatting --- src/metrics/delta.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/metrics/delta.rs b/src/metrics/delta.rs index 28220cd7..24a52ce9 100644 --- a/src/metrics/delta.rs +++ b/src/metrics/delta.rs @@ -1,3 +1,4 @@ +use num_format::ToFormattedStr; use std::fmt::{Debug, Display, Formatter, Write}; pub trait DeltaValue: Copy + Debug + Display { @@ -140,6 +141,18 @@ pub trait DeltaTo { fn delta_to(&mut self, other: &Self); } +pub struct Formatted(pub T); + +impl Display for Formatted { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + use num_format::{Locale, ToFormattedString}; + + f.write_str(&self.0.to_formatted_string(&Locale::en))?; + + Ok(()) + } +} + #[cfg(test)] mod test { use super::*;