From 7658af7ceab0813c4041d9953cc71680928dcbf7 Mon Sep 17 00:00:00 2001 From: thunderstorm010 Date: Sat, 21 Mar 2026 23:45:50 +0300 Subject: [PATCH] Fix units KB->KiB,MB->MiB,GB->GiB Also add gitignore --- .gitignore | 1 + src/main.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6c806c5..9e53dbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,13 +30,13 @@ fn get_folder_size(path: &str) -> u64 { } fn human_readable_size(size: u64) -> String { - const KB: u64 = 1024; - const MB: u64 = KB * 1024; - const GB: u64 = MB * 1024; + const KIB: u64 = 1024; + const MIB: u64 = KIB * 1024; + const GIB: u64 = MIB * 1024; match size { - s if s >= GB => format!("{:.2} GB", s as f64 / GB as f64), - s if s >= MB => format!("{:.2} MB", s as f64 / MB as f64), - s if s >= KB => format!("{:.2} KB", s as f64 / KB as f64), + s if s >= GIB => format!("{:.2} GiB", s as f64 / GIB as f64), + s if s >= MIB => format!("{:.2} MiB", s as f64 / MIB as f64), + s if s >= KIB => format!("{:.2} KiB", s as f64 / KIB as f64), _ => format!("{} B", size), } }