Skip to content

Commit 4174cc9

Browse files
committed
limit fractional part in size
1 parent d928657 commit 4174cc9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/info/size.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fn get_repo_size(repo: &Repository) -> (String, u64) {
4040

4141
fn bytes_to_human_readable(bytes: u64) -> String {
4242
let byte = Byte::from_u64(bytes);
43-
byte.get_appropriate_unit(UnitType::Binary).to_string()
43+
let adjusted_byte_based = byte.get_appropriate_unit(UnitType::Binary);
44+
format!("{adjusted_byte_based:#.2}")
4445
}
4546

4647
impl std::fmt::Display for SizeInfo {
@@ -115,7 +116,8 @@ mod test {
115116
case(1024, "1 KiB"),
116117
case(2048, "2 KiB"),
117118
case(1048576, "1 MiB"),
118-
case(1099511627776, "1 TiB")
119+
case(1099511627776, "1 TiB"),
120+
case(2577152, "2.46 MiB")
119121
)]
120122
fn test_bytes_to_human_readable(#[case] input: u64, #[case] expected: &str) {
121123
assert_eq!(bytes_to_human_readable(input), expected);

0 commit comments

Comments
 (0)