diff --git a/cli/src/util.rs b/cli/src/util.rs index bea0967..9c4b277 100644 --- a/cli/src/util.rs +++ b/cli/src/util.rs @@ -17,7 +17,16 @@ pub fn ser_size_mb(size: &usize, serializer: S) -> Result where S: Serializer, { - serializer.serialize_str(&format!("{:.2} MB", *size as f64 / 1024. / 1024.)) + fn format_with_commas(num: &usize) -> String { + let s = num.to_string(); + + s.as_bytes().rchunks(3).map(String::from_utf8_lossy).rev().collect::>().join(",") + } + + let mb = *size as f64 / (1024. * 1024.); + let bytes = format_with_commas(size); + + serializer.serialize_str(&format!("{mb:.2} MB ({bytes} bytes)")) } #[test] @@ -41,6 +50,6 @@ fn ser_should_work() { size: 1024 * 1024 }) .unwrap(), - r#"{"time":"2021-08-01T00:00:00+00:00","size":"1.00 MB"}"# + r#"{"time":"2021-08-01T00:00:00+00:00","size":"1.00 MB (1,048,576 bytes)"}"# ) }