Skip to content

Commit

Permalink
Adjust mega precision
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Sep 6, 2024
1 parent 6070fc5 commit 1c7a6f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl fmt::Display for Pretty<f32> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let value = self.0;
match value {
Self::MEGA_MIN.. => write!(f, "{:.1}M", value / Self::MEGA),
Self::MEGA_MIN.. => write!(f, "{:.2}M", value / Self::MEGA),
Self::KILO_MIN.. => write!(f, "{:.1}k", value / Self::KILO),
_ => write!(f, "{value:.1}"),
}
Expand All @@ -44,7 +44,7 @@ impl fmt::Display for Pretty<u32> {

let value = self.0;
match value {
MEGA_MIN.. => write!(f, "{:.1}M", value as f32 / Self::MEGA),
MEGA_MIN.. => write!(f, "{:.2}M", value as f32 / Self::MEGA),
KILO_MIN.. => write!(f, "{:.1}k", value as f32 / Self::KILO),
_ => write!(f, "{value}"),
}
Expand All @@ -61,7 +61,7 @@ mod tests {
assert_eq!(Pretty(123).to_string(), "123");
assert_eq!(Pretty(10_000).to_string(), "10.0k");
assert_eq!(Pretty(76_590).to_string(), "76.6k");
assert_eq!(Pretty(1_390_000).to_string(), "1.4M");
assert_eq!(Pretty(1_239_000).to_string(), "1.24M");
}

#[test]
Expand All @@ -70,6 +70,6 @@ mod tests {
assert_eq!(Pretty(123.49).to_string(), "123.5");
assert_eq!(Pretty(10_000.0).to_string(), "10.0k");
assert_eq!(Pretty(76_590.0).to_string(), "76.6k");
assert_eq!(Pretty(1_390_000.0).to_string(), "1.4M");
assert_eq!(Pretty(1_239_000.0).to_string(), "1.24M");
}
}

0 comments on commit 1c7a6f0

Please sign in to comment.