(bytes: f64, fraction_digits: Option<usize>)
| 23 | } |
| 24 | |
| 25 | pub(crate) fn format_memory(bytes: f64, fraction_digits: Option<usize>) -> String { |
| 26 | let fraction_digits = fraction_digits.unwrap_or(1); // Default to 1 decimal place |
| 27 | |
| 28 | if bytes == 0.0 { |
| 29 | return "0 B".to_string(); |
| 30 | } |
| 31 | |
| 32 | let unit_index = get_unit_index(bytes); |
| 33 | let unit = UNITS[unit_index]; |
| 34 | let shifted_value = bytes / BASE.powi(unit_index as i32); |
| 35 | |
| 36 | format!( |
| 37 | "{} {}", |
| 38 | format_shifted_value(shifted_value, fraction_digits), |
| 39 | unit |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | #[cfg(test)] |
| 44 | mod tests { |
no test coverage detected