pub trait Smooth {
// Required methods
fn round_to(&self, decimals: u32) -> Self;
fn round_to_mut(&mut self, decimals: u32);
fn round_to_str(&self, decimals: u32) -> String;
fn smooth(&self) -> Self;
fn smooth_mut(&mut self);
fn smooth_str(&self) -> String;
}
Expand description
Extension trait to make a single number human-readable.
Required Methods§
sourcefn round_to(&self, decimals: u32) -> Self
fn round_to(&self, decimals: u32) -> Self
Returns the number rounded to the specified decimals.
Examples
assert_eq!(1.1111.round_to(2), 1.11);
assert_eq!(9.9999.round_to(2), 10.0);
sourcefn round_to_mut(&mut self, decimals: u32)
fn round_to_mut(&mut self, decimals: u32)
Rounds the number to the specified decimals.
Examples
let mut n = 1.1111;
n.round_to_mut(2);
assert_eq!(n, 1.11);
sourcefn round_to_str(&self, decimals: u32) -> String
fn round_to_str(&self, decimals: u32) -> String
Returns the formatted, rounded number.
Examples
assert_eq!(1.0.round_to_str(2), "1");
assert_eq!(1.001.round_to_str(2), "1");
assert_eq!(1.018.round_to_str(2), "1.02");
assert_eq!(1.4242.round_to_str(2), "1.42");
sourcefn smooth(&self) -> Self
fn smooth(&self) -> Self
Returns the smoothed number.
Examples
assert_eq!(0.0.smooth(), 0.0);
assert_eq!(0.009.smooth(), 0.01);
assert_eq!(1.001.smooth(), 1.0);
assert_eq!(10.1.smooth(), 10.1);
assert_eq!(1000.9.smooth(), 1001.0);
sourcefn smooth_mut(&mut self)
fn smooth_mut(&mut self)
sourcefn smooth_str(&self) -> String
fn smooth_str(&self) -> String
Returns the formatted, smoothed number.
Examples
assert_eq!(0.0.smooth_str(), "0");
assert_eq!(0.009.smooth_str(), "0.01");
assert_eq!(1.001.smooth_str(), "1");
assert_eq!(10.1.smooth_str(), "10.1");
assert_eq!(1000.9.smooth_str(), "1001");