Expand description
§numan — humanize numbers
Turn raw numbers into the short, human-readable strings you see in dashboards, CLIs and reports — and parse them back.
assert_eq!(numan::compact(1_234), "1.2K");
assert_eq!(numan::word(1_200_000), "1.2 million");
assert_eq!(numan::metric(1_500), "1.5 k");
assert_eq!(numan::ordinal(22), "22nd");
assert_eq!(numan::parse("1.5M").unwrap(), 1_500_000.0);§Why numan?
Rust already has great crates for file sizes (humansize) and relative
time (chrono-humanize). numan fills the remaining gap from Python’s
humanize and Go’s go-humanize: shortening the magnitude of plain
numbers — 1.2K, 1.2 million, 1.2 k — with a single focused,
zero-dependency, #![no_std] crate.
§Configuring output
Use Formatter for full control over precision, spacing and sign:
use numan::Formatter;
let f = Formatter::compact().precision(2).space(true);
assert_eq!(f.format(1_234_567), "1.23 M");Structs§
- Formatter
- A configurable number humanizer.
Enums§
- Notation
- Which family of suffixes to use when shortening a number.
- Parse
Error - Error returned by
parsewhen the input is not a recognizable number.
Traits§
- Integer
- Any primitive signed/unsigned integer, used by
crate::ordinal. - Number
- Any primitive number that can be humanized.
Functions§
- compact
- Format a number in compact notation:
1_234→"1.2K". - metric
- Format a number in SI metric notation:
1_500→"1.5 k". - ordinal
- Format an integer with its English ordinal suffix:
1→"1st",22→"22nd",113→"113th". - parse
- Parse a humanized number such as
"1.2K","1.5 million","3M"or"-2.5bn"back into anf64. - word
- Format a number in word notation:
1_200_000→"1.2 million".