Skip to main content

format_bytes_full

Function format_bytes_full 

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

Format bytes with variable precision and full unit labels.

Uses 1024-based thresholds. TB and GB use 2 decimal places for precision; MB and KB use 1 decimal place. Values below 1024 show the raw count with “ B“ suffix. Intended for transfer totals and PCIe bandwidth displays.

§Examples

use batuta_common::fmt::format_bytes_full;
assert_eq!(format_bytes_full(1_099_511_627_776), "1.00 TB");
assert_eq!(format_bytes_full(1_073_741_824), "1.00 GB");
assert_eq!(format_bytes_full(1_048_576), "1.0 MB");
assert_eq!(format_bytes_full(1024), "1.0 KB");
assert_eq!(format_bytes_full(500), "500 B");