Skip to main content

format_bytes_compact

Function format_bytes_compact 

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

Format bytes compactly with short IEC-based units and no spaces.

Uses 1024-based thresholds with single-letter units (K, M, G, T) and 1 decimal place. Values below 1024 are shown as fractional K. Intended for tight UI columns like disk panels.

ยงExamples

use batuta_common::fmt::format_bytes_compact;
assert_eq!(format_bytes_compact(1_073_741_824), "1.0G");
assert_eq!(format_bytes_compact(1_048_576), "1.0M");
assert_eq!(format_bytes_compact(1024), "1.0K");
assert_eq!(format_bytes_compact(512), "0.5K");