Skip to main content

format_bytes

Function format_bytes 

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

Format a byte count with binary units (B, KiB, MiB, GiB, TiB). Values below 1 KiB are rendered as the exact byte count; everything larger uses one decimal.

use microsandbox_utils::format::format_bytes;
assert_eq!(format_bytes(0), "0 B");
assert_eq!(format_bytes(1023), "1023 B");
assert_eq!(format_bytes(1024), "1.0 KiB");
assert_eq!(format_bytes(14_628_864), "14.0 MiB");