From dbc73a4d1a5606e86796aedbe7d814daa7f39141 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 2 Sep 2020 15:51:07 +0200 Subject: fix(formatting): improve accuracy (#178) * fix(formatting): improve accuracy * style(format): line length * fix(formatting): use mebi/gibi/tibi bytes * style(format): fmt --- src/display/components/display_bandwidth.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/display/components/display_bandwidth.rs b/src/display/components/display_bandwidth.rs index 04f1e89..ff2dcce 100644 --- a/src/display/components/display_bandwidth.rs +++ b/src/display/components/display_bandwidth.rs @@ -9,13 +9,19 @@ impl fmt::Display for DisplayBandwidth { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let suffix = if self.as_rate { "ps" } else { "" }; if self.bandwidth > 999_999_999_999.0 { - write!(f, "{:.2}TB{}", self.bandwidth / 1_000_000_000_000.0, suffix) + // 1024 * 1024 * 1024 * 1024 + write!( + f, + "{:.2}TiB{}", + self.bandwidth / 1_099_511_627_776.0, + suffix + ) } else if self.bandwidth > 999_999_999.0 { - write!(f, "{:.2}GB{}", self.bandwidth / 1_000_000_000.0, suffix) + write!(f, "{:.2}GiB{}", self.bandwidth / 1_073_741_824.0, suffix) // 1024 * 1024 * 1024 } else if self.bandwidth > 999_999.0 { - write!(f, "{:.2}MB{}", self.bandwidth / 1_000_000.0, suffix) + write!(f, "{:.2}MiB{}", self.bandwidth / 1_048_576.0, suffix) // 1024 * 1024 } else if self.bandwidth > 999.0 { - write!(f, "{:.2}KB{}", self.bandwidth / 1000.0, suffix) + write!(f, "{:.2}KiB{}", self.bandwidth / 1024.0, suffix) } else { write!(f, "{}B{}", self.bandwidth, suffix) } -- cgit v1.2.3