Format a count to a nice representation optimized for human readability.
(x: u64)
| 111 | |
| 112 | /// Format a count to a nice representation optimized for human readability. |
| 113 | pub fn humanize_count(x: u64) -> HumanCount { |
| 114 | if x > 10u64.pow(9) { |
| 115 | HumanCount(x as f32 / 1e9, 2, "B") |
| 116 | } else if x > 10u64.pow(6) { |
| 117 | HumanCount(x as f32 / 1e6, 2, "M") |
| 118 | } else if x > 10u64.pow(3) { |
| 119 | HumanCount(x as f32 / 1e3, 2, "K") |
| 120 | } else { |
| 121 | HumanCount(x as f32, 0, "") |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #[derive(Debug)] |
| 126 | pub struct HumanCount(f32, usize, &'static str); |
no test coverage detected