Format sizes with base 10 units
This commit is contained in:
parent
583ba6c22d
commit
eede1c773d
1 changed files with 12 additions and 12 deletions
24
src/tab.rs
24
src/tab.rs
|
|
@ -115,19 +115,19 @@ fn trash_icon_symbolic(icon_size: u16) -> widget::icon::Handle {
|
||||||
|
|
||||||
//TODO: translate, add more levels?
|
//TODO: translate, add more levels?
|
||||||
fn format_size(size: u64) -> String {
|
fn format_size(size: u64) -> String {
|
||||||
const KIB: u64 = 1024;
|
const KB: u64 = 1000;
|
||||||
const MIB: u64 = 1024 * KIB;
|
const MB: u64 = 1000 * KB;
|
||||||
const GIB: u64 = 1024 * MIB;
|
const GB: u64 = 1000 * MB;
|
||||||
const TIB: u64 = 1024 * GIB;
|
const TB: u64 = 1000 * GB;
|
||||||
|
|
||||||
if size >= 4 * TIB {
|
if size >= TB {
|
||||||
format!("{:.1} TiB", size as f64 / TIB as f64)
|
format!("{:.1} TB", size as f64 / TB as f64)
|
||||||
} else if size >= GIB {
|
} else if size >= GB {
|
||||||
format!("{:.1} GiB", size as f64 / GIB as f64)
|
format!("{:.1} GB", size as f64 / GB as f64)
|
||||||
} else if size >= MIB {
|
} else if size >= MB {
|
||||||
format!("{:.1} MiB", size as f64 / MIB as f64)
|
format!("{:.1} MB", size as f64 / MB as f64)
|
||||||
} else if size >= KIB {
|
} else if size >= KB {
|
||||||
format!("{:.1} KiB", size as f64 / KIB as f64)
|
format!("{:.1} KB", size as f64 / KB as f64)
|
||||||
} else {
|
} else {
|
||||||
format!("{} B", size)
|
format!("{} B", size)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue