abbrev-num 0.1.0

Abbreviate numbers into a human-friendly format
Documentation
  • Coverage
  • 85.71%
    6 out of 7 items documented1 out of 3 items with examples
  • Size
  • Source code size: 10.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.91 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • zignis/abbrev-num
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zignis

abbrev-num

Abbreviate numbers into a human-friendly format

Examples

Basic

use abbrev_num::abbrev_num;

assert_eq!(abbrev_num(1_400, None), Some("1.4k".to_string()));

Precision

use abbrev_num::{abbrev_num, Options};

let options = Options {
    precision: Some(2),
    ..Default::default()
};

assert_eq!(abbrev_num(1_420, Some(options)), Some("1.42k".to_string()));

Custom units

use abbrev_num::{abbrev_num, Options};

let units: [&str; 7] = ["mm", "cm", "m", "km", "", "", ""];
let options = Options {
    abbreviations: Some(units),
    ..Default::default()
};

assert_eq!(abbrev_num(1_400, Some(options)), Some("1.4cm".to_string()));

Custom rounding strategy

use abbrev_num::{abbrev_num, Options, RoundingStrategy};

let options = Options {
    rounding_strategy: Some(RoundingStrategy::ToZero),
    precision: Some(0),
    ..Default::default()
};

assert_eq!(abbrev_num(1_566_450, Some(options)), Some("1M".to_string()));