Skip to main content

format_bytes

Function format_bytes 

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

Format bytes in human-readable form (IEC-style with short units).

Uses “KB”, “MB”, “GB” labels (1024-based) with 1 decimal place. This is the most common format for CLI output.

§Examples

use batuta_common::fmt::format_bytes;
assert_eq!(format_bytes(0), "0 B");
assert_eq!(format_bytes(1023), "1023 B");
assert_eq!(format_bytes(1024), "1.0 KB");
assert_eq!(format_bytes(1_048_576), "1.0 MB");