Trait smooth::Smooth

source ·
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§

source

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);
source

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);
source

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");
source

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);
source

fn smooth_mut(&mut self)

Smoothes the number.

Examples
let mut n = 1.001;
n.smooth_mut();

assert_eq!(n, 1.0);
source

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");

Implementations on Foreign Types§

source§

impl Smooth for f32

source§

fn round_to(&self, decimals: u32) -> Self

source§

fn round_to_mut(&mut self, decimals: u32)

source§

fn round_to_str(&self, decimals: u32) -> String

source§

fn smooth(&self) -> Self

source§

fn smooth_mut(&mut self)

source§

fn smooth_str(&self) -> String

source§

impl Smooth for f64

source§

fn round_to(&self, decimals: u32) -> Self

source§

fn round_to_mut(&mut self, decimals: u32)

source§

fn round_to_str(&self, decimals: u32) -> String

source§

fn smooth(&self) -> Self

source§

fn smooth_mut(&mut self)

source§

fn smooth_str(&self) -> String

Implementors§