Browse Source

limit fractional part in size

pull/1222/head
o2sh 2 years ago
parent
commit
4174cc998c
No known key found for this signature in database
GPG Key ID: 8E776BBC825CF3E3
  1. 6
      src/info/size.rs

6
src/info/size.rs

@ -40,7 +40,8 @@ fn get_repo_size(repo: &Repository) -> (String, u64) { @@ -40,7 +40,8 @@ fn get_repo_size(repo: &Repository) -> (String, u64) {
fn bytes_to_human_readable(bytes: u64) -> String {
let byte = Byte::from_u64(bytes);
byte.get_appropriate_unit(UnitType::Binary).to_string()
let adjusted_byte_based = byte.get_appropriate_unit(UnitType::Binary);
format!("{adjusted_byte_based:#.2}")
}
impl std::fmt::Display for SizeInfo {
@ -115,7 +116,8 @@ mod test { @@ -115,7 +116,8 @@ mod test {
case(1024, "1 KiB"),
case(2048, "2 KiB"),
case(1048576, "1 MiB"),
case(1099511627776, "1 TiB")
case(1099511627776, "1 TiB"),
case(2577152, "2.46 MiB")
)]
fn test_bytes_to_human_readable(#[case] input: u64, #[case] expected: &str) {
assert_eq!(bytes_to_human_readable(input), expected);

Loading…
Cancel
Save