summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2020-09-02 15:51:07 +0200
committerGitHub <noreply@github.com>2020-09-02 15:51:07 +0200
commitdbc73a4d1a5606e86796aedbe7d814daa7f39141 (patch)
tree7bdb2c46edf18a8e4f5e2babf0980a778e742cc5
parent8b4bdf07891fea614b2705ceb568981feb73940e (diff)
fix(formatting): improve accuracy (#178)
* fix(formatting): improve accuracy * style(format): line length * fix(formatting): use mebi/gibi/tibi bytes * style(format): fmt
-rw-r--r--src/display/components/display_bandwidth.rs14
1 files 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)
}