pub struct Formatter<const BASE: usize = 0, const DECIMALS: usize = 2> { /* private fields */ }humat instead, this crate will be removed in the future.Expand description
Entry point to the lib. Use this to handle your formatting needs.
BASE: the baseDECIMALS: target decimal places (if not keeping the original number)
Implementations§
Source§impl Formatter
impl Formatter
Source§impl<const BASE: usize, const DECIMALS: usize> Formatter<BASE, DECIMALS>
impl<const BASE: usize, const DECIMALS: usize> Formatter<BASE, DECIMALS>
Sourcepub const fn new(units: &'static [&'static str]) -> Self
👎Deprecated: use humat instead, this crate will be removed in the future.
pub const fn new(units: &'static [&'static str]) -> Self
humat instead, this crate will be removed in the future.Create a new Formatter with given BASE, DECIMALS and units.
Sourcepub const fn with_separator(self, separator: &'static str) -> Self
👎Deprecated: use humat instead, this crate will be removed in the future.
pub const fn with_separator(self, separator: &'static str) -> Self
humat instead, this crate will be removed in the future.Set the separator between numbers and units.
Sourcepub const fn with_scales<const N_BASE: usize>(
self,
units: &'static [&'static str],
) -> Formatter<N_BASE, DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub const fn with_scales<const N_BASE: usize>( self, units: &'static [&'static str], ) -> Formatter<N_BASE, DECIMALS>
humat instead, this crate will be removed in the future.Set scales, including base and the abbreviated number’s units.
Sourcepub const fn with_custom_unit(self, custom_unit: &'static str) -> Self
👎Deprecated: use humat instead, this crate will be removed in the future.
pub const fn with_custom_unit(self, custom_unit: &'static str) -> Self
humat instead, this crate will be removed in the future.Set custom unit attached after the abbreviated number’s unit.
Sourcepub const fn with_decimals<const N_DECIMALS: usize>(
self,
) -> Formatter<BASE, N_DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub const fn with_decimals<const N_DECIMALS: usize>( self, ) -> Formatter<BASE, N_DECIMALS>
humat instead, this crate will be removed in the future.Set the decimal places to keep.
Sourcepub fn format(&self, number: impl NumberT) -> FormatResult<DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub fn format(&self, number: impl NumberT) -> FormatResult<DECIMALS>
humat instead, this crate will be removed in the future.Formats the given number into a human-readable string using the
specified units and separator.
See NumberT for all types we accept as param.
§Notice
For better performance (may be so), you may need
format_int or format_uint.
§Limitation
f64 can only handle 15 decimal places at most. We may introduce
macro_toolset for large number formatting.
Sourcepub fn format_int(&self, number: impl Into<i128>) -> FormatResult<DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub fn format_int(&self, number: impl Into<i128>) -> FormatResult<DECIMALS>
humat instead, this crate will be removed in the future.Formats the given number into a human-readable string using the
specified units and separator.
We accept any number that fits into isize. For i128, see
format_large_int.
Sourcepub fn format_uint(&self, number: impl Into<u128>) -> FormatResult<DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub fn format_uint(&self, number: impl Into<u128>) -> FormatResult<DECIMALS>
humat instead, this crate will be removed in the future.Formats the given number into a human-readable string using the
specified units and separator.
Sourcepub fn format_general(
&self,
integer: u128,
fraction: Option<f64>,
) -> FormatResult<DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub fn format_general( &self, integer: u128, fraction: Option<f64>, ) -> FormatResult<DECIMALS>
humat instead, this crate will be removed in the future.Formats the given number into a human-readable string using the
specified units and separator.
§Params
integer: the integer part of the number.- For float,
f32::truncorf64::truncmay helps you.
- For float,
fraction: the fractional part of the number.- For float,
f32::fractorf64::fractmay helps you. - For integer, leave it
None.
- For float,
§Notice
It’s NOT recommended that you use this directly, use
format instead unless you know exactly what you do.
Sourcepub fn format_float(&self, number: f64) -> FormatResult<DECIMALS>
👎Deprecated: use humat instead, this crate will be removed in the future.
pub fn format_float(&self, number: f64) -> FormatResult<DECIMALS>
humat instead, this crate will be removed in the future.