Crate digit_group [] [src]

This crate provides grouping (aka "thousands separators") for numeric types.


Typical use-case to format a number with groups sized 3 (United States):

use digit_group::FormatGroup;

let x = 123456789;
assert_eq!(x.format_commas(), "123,456,789")

Formatting based on SI standards (with custom decimal mark):

use digit_group::FormatGroup;

let x: f64 = 123456789.01234;
assert_eq!(x.format_si('.'), "123 456 789.012 34")

Completely custom decimal mark, grouping delimiter, initial group size, and subsequent group size:

use digit_group::FormatGroup;

let x: f64 = 123456789.01;
assert_eq!(x.format_custom('#',':',4,2, false), "1:23:45:6789#01")

Using format! to change the precision of a value prior to grouping:

use digit_group::custom_group;

let val: f64 = 111222.3;
let formatted = format!("{:.3}", val);
let grouped = custom_group(&formatted, ',', ' ', 3, 3, false);
assert_eq!(grouped, "111 222,300");



Various formatters provided for integer grouping.



Groups a pre-formatted number passed as a &str. For use with numbers formatted with format! to set significant digits, padding, etc.