Crates.io | abbrev-num |
lib.rs | abbrev-num |
version | 0.1.0 |
source | src |
created_at | 2024-04-07 15:15:17.498025 |
updated_at | 2024-04-07 15:15:17.498025 |
description | Abbreviate numbers into a human-friendly format |
homepage | |
repository | https://github.com/zignis/abbrev-num.git |
max_upload_size | |
id | 1199238 |
size | 9,773 |
Abbreviate numbers into a human-friendly format
use abbrev_num::abbrev_num;
assert_eq!(abbrev_num(1_400, None), Some("1.4k".to_string()));
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()));
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()));
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()));