pub trait Round {
// Required methods
fn round_to(&mut self, decimal_places: u32) -> f64;
fn with_significant_figures(&mut self, digits: u64) -> Self;
}
Expand description
Allows the usage of rounding methods that are more specific than rust std’s round() method.
Required Methods§
Sourcefn round_to(&mut self, decimal_places: u32) -> f64
fn round_to(&mut self, decimal_places: u32) -> f64
Rounds self (a number) to the given number of decimal places. This method is mainly made for the f32 and f64 types since integer types already have no decimal places.
Example:
assert_eq!(23.3274.round_to(2), 23.33);
assert_eq!((1. / 3.).round_to(5), 0.33333);
// For integer types, rounding to a decimal point is the same as casting it to f64
assert_eq!(100_u8.round_to(10), 100.);
Sourcefn with_significant_figures(&mut self, digits: u64) -> Self
fn with_significant_figures(&mut self, digits: u64) -> Self
Rounds self (a number) to the given number of significant figures. Example:
assert_eq!(14912387964_u128.with_significant_figures(5), 14912000000);
assert_eq!(-4095_i32.with_significant_figures(1), -4000);
assert_eq!(1234.5678_f64.with_significant_figures(6), 1234.57)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.