Struct re_format::FloatFormatOptions
source · pub struct FloatFormatOptions {
pub always_sign: bool,
pub precision: usize,
pub num_decimals: Option<usize>,
pub strip_trailing_zeros: bool,
pub min_decimals_for_thousands_separators: usize,
}
Expand description
Options for how to format a floating point number, e.g. an f64
.
Fields§
§always_sign: bool
Always show the sign, even if it is positive (+
).
precision: usize
Maximum digits of precision to use.
This includes both the integer part and the fractional part.
num_decimals: Option<usize>
Max number of decimals to show after the decimal point.
If not specified, Self::precision
is used instead.
strip_trailing_zeros: bool
§min_decimals_for_thousands_separators: usize
Only add thousands separators to decimals if there are at least this many decimals.
Implementations§
source§impl FloatFormatOptions
impl FloatFormatOptions
sourcepub const DEFAULT_f32: Self = _
pub const DEFAULT_f32: Self = _
Default options for formatting an f32
.
sourcepub const DEFAULT_f64: Self = _
pub const DEFAULT_f64: Self = _
Default options for formatting an f64
.
sourcepub fn with_always_sign(self, always_sign: bool) -> Self
pub fn with_always_sign(self, always_sign: bool) -> Self
Always show the sign, even if it is positive (+
).
sourcepub fn with_precision(self, precision: usize) -> Self
pub fn with_precision(self, precision: usize) -> Self
Show at most this many digits of precision, including both the integer part and the fractional part.
sourcepub fn with_decimals(self, num_decimals: usize) -> Self
pub fn with_decimals(self, num_decimals: usize) -> Self
Max number of decimals to show after the decimal point.
If not specified, Self::precision
is used instead.
sourcepub fn with_strip_trailing_zeros(self, strip_trailing_zeros: bool) -> Self
pub fn with_strip_trailing_zeros(self, strip_trailing_zeros: bool) -> Self
Strip trailing zeros from decimal expansion?
sourcepub fn format(&self, value: impl Into<f64>) -> String
pub fn format(&self, value: impl Into<f64>) -> String
The returned value is for human eyes only, and can not be parsed
by the normal f64::from_str
function.
pub(crate) fn format_f64(&self, value: f64) -> String
Trait Implementations§
source§impl Clone for FloatFormatOptions
impl Clone for FloatFormatOptions
source§fn clone(&self) -> FloatFormatOptions
fn clone(&self) -> FloatFormatOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FloatFormatOptions
impl Debug for FloatFormatOptions
source§impl Hash for FloatFormatOptions
impl Hash for FloatFormatOptions
source§impl PartialEq for FloatFormatOptions
impl PartialEq for FloatFormatOptions
source§fn eq(&self, other: &FloatFormatOptions) -> bool
fn eq(&self, other: &FloatFormatOptions) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for FloatFormatOptions
impl Eq for FloatFormatOptions
impl StructuralPartialEq for FloatFormatOptions
Auto Trait Implementations§
impl Freeze for FloatFormatOptions
impl RefUnwindSafe for FloatFormatOptions
impl Send for FloatFormatOptions
impl Sync for FloatFormatOptions
impl Unpin for FloatFormatOptions
impl UnwindSafe for FloatFormatOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)