Trait digit_group::FormatGroup [] [src]

pub trait FormatGroup {
    fn format_si(&self, decimal_mark: char) -> String;
    fn format_commas(&self) -> String;
    fn format_custom(
        &self,
        decimal_mark: char,
        grouping_delimiter: char,
        first_group_size: usize,
        group_size: usize,
        group_fractional_part: bool
    ) -> String; }

Various formatters provided for integer grouping.

Required Methods

Formats the number according to ISO 80000-1, using a custom decimal_mark.

Example

use digit_group::FormatGroup;

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

Formats the integral value into groups of three, separated by commas.

Example

use digit_group::FormatGroup;

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

Formats the number based on supplied parameters.

decimal_mark is the char used to delimit the integer and fractional portions of the number.

grouping_delimiter is the delimiter to use between groups.

first_group_size is the number of digits of the initial group.

group_size is the number of digits of subsequent groups.

group_fractional_part determines whether to apply the above grouping rules to the decimal portion of the number.

Example

use digit_group::FormatGroup;

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

Implementors