Skip to main content

bytes

Function bytes 

pub fn bytes(n: u64) -> String
Expand description

Format a byte count with base-1024 IEC binary units (B, KiB, MiB, GiB, TiB, …). Whole bytes print with no decimal; larger units print one decimal place.

use tilo_ui::format::bytes;
assert_eq!(bytes(0), "0 B");
assert_eq!(bytes(512), "512 B");
assert_eq!(bytes(1023), "1023 B");
assert_eq!(bytes(1024), "1.0 KiB");
assert_eq!(bytes(5 * 1024 * 1024), "5.0 MiB");