Skip to main content

compact_count

Function compact_count 

pub fn compact_count(n: u64) -> String
Expand description

Abbreviate a large count to at most one fractional digit: 1.2K, 3.4M, 1.1B. Exact tenths omit the redundant .0 (12K, not 12.0K) and a value that rounds into the next unit is promoted (999_999 becomes 1M, never 1000.0K). Values below 1000 print in full.

use tilo_ui::format::compact_count;
assert_eq!(compact_count(0), "0");
assert_eq!(compact_count(999), "999");
assert_eq!(compact_count(12_300), "12.3K");
assert_eq!(compact_count(4_100_000), "4.1M");
assert_eq!(compact_count(1_100_000_000), "1.1B");