Skip to content

Commit

Permalink
fix: bug: Si detection was backwards.
Browse files Browse the repository at this point in the history
kB - means kilobyte 10**3
KiB - means kibibyte 1024 / 2**10

https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
  • Loading branch information
bootandy committed Apr 27, 2024
1 parent ecd6b85 commit 1a642f6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,14 @@ fn get_pretty_name(

// If we are working with SI units or not
pub fn get_type_of_thousand(output_str: &str) -> u64 {
let is_si = output_str.contains('i'); // si, KiB, MiB, etc
if is_si {
if output_str.is_empty() {
1024
}else if output_str == "si" {
1000
} else {
} else if output_str.contains('i') {
1024
} else {
1000
}
}

Expand Down Expand Up @@ -550,6 +553,8 @@ mod tests {
fn test_human_readable_number_si() {
assert_eq!(human_readable_number(1024 * 100, ""), "100K");
assert_eq!(human_readable_number(1024 * 100, "si"), "102K");
assert_eq!(human_readable_number(1024 * 100, "kB"), "102K");
assert_eq!(human_readable_number(1024 * 100, "kiB"), "100K");
}

#[test]
Expand Down

0 comments on commit 1a642f6

Please sign in to comment.