Trait ToFormat

Source
pub trait ToFormat {
    // Required method
    fn to_format(
        self,
        format: &str,
        culture: Culture,
    ) -> Result<String, ConversionError>;
}
Expand description

Trait to display a number with ‘to_format’ function The format parameter is like C# toString() function with N0 / N2 / N4 values N0 display 0 digit, N2 two digit, N4 four digit etc. The max is N9 digit And the culture parameter is use to display with the selected culture (it automatically apply the thousand and decimal separator of the given culture)

§Example

use num_string::{Culture, ToFormat};
    assert_eq!(1000.to_format("N0", Culture::English).unwrap(), "1,000");
    assert_eq!(1000.to_format("N2", Culture::French).unwrap(), "1 000,00");

Required Methods§

Source

fn to_format( self, format: &str, culture: Culture, ) -> Result<String, ConversionError>

Implementors§

Source§

impl<T> ToFormat for T
where T: Num + Display,

Implement the trait for all primitive (i8, i64, u32, f32 etc.), thanks to Num trait